- Book Review Api: Django Rest Framework with Faker and Requests Library
- Models: Book, Comment, User
- API Endpoints:
- api/book-view
- api/book-view/{bookId}
- api/comment-view/{commentId}
- api/book-view/{bookId}/comment
- Built-in sqlite database is NOT populated. You can populate it with the admin panel as a superuser.
PS: > python manage.py makemigrations
PS: > python manage.py migrate
PS: > python manage.py createsuperuser
Some Specs:
- One-to-many(Foreign Key) relation models including built-in User model.
- Validators as a model field attribute.
- Nested ModelSerializers with the use of related_name model attribute preventing integrity error, and StringRelatedField for better naming convention.
- Generics class with perform_create overwrite.
- Built-in and Custom Permissions
- Preventing multiple comments from the same user.
- A user can see only its own comment.
- Pagination
- Populating User and Book models using Faker and requests library.(fake_data.py in scripts folder)
Some Important Notes:
- For the User model, the user creation is not handled by the endpoint, use either fake_data.py script or the admin panel to create it. There is a pipfile for fast-installing the related libraries, for which you need to install pipenv first, which combines the functionalities of pip and venv. The command below will automatically install all necessary libraries.
PS: > pipenv install
- Before starting the server with the following command, make sure you use the python interpreter that belongs to the virtual environment you created.
PS: > python manage.py runserver
- Make sure you login first before using the endpoints since they ask for authentication.