Django Rest Framework
A Django
refresher
Introduction
Welcome to the second part of the series. If you missed the first part, you could read it here.
Guiding questions
I believe that these questions will be a great guide to forming a structure of understanding. Oh! there’s also a diagram accompanying this part.
How does Django handle requests?
In views.py, we would define a url pattern and then specify a function associated with the pattern.
How does Django manage database tables?
We can think of models roughly as tables. We define models in models.py. After we define a model, we need to make migrations:
poetry run python manage.py makemigrations
makemigrations detect changes of the model. The changes will be generated in the migrations directory.
After that, we can migrate (push) changes to the database by executing:
poetry run python manage.py migrate
How to define and compose permissions?
We generally define permissions in permissions.py. Permissions can also be grouped by & (AND), | (OR) and ~ (NOT).
How to verify the JSON submitted from the front-end?
serializers.py contains field constraints. A serializer acts as a guardian of the database. It governs how data gets in (saved to database) and out (sent as a JSON object).
Outro
All important points were introduced and lightly touched. Details will be filled as we go. Thank you for your attention, and see you next time!!