Course Content
Django REST Framework
Django REST Framework
Overview of Models
Where do the data displayed on a website or mobile app come from?
For instance, if you're creating a blog, you need to store information about articles, comments, and users. Models in Django REST Framework (DRF) define the structure of this data. They serve as a way to organize and store data in your application. When you define models, DRF can use them to create an API that allows your clients (such as web pages or mobile apps) to access this data over the internet. Thus, models are the foundation of your application, enabling it to work with stored data and provide them through an API.
The Application Model We Will Develop Throughout the Course
Model will store information about a product, such as its name, description, price, available quantity, and the path to an image (here will be stored either a link to an image or the local path to it).
As we can see in the illustrations, all this information will be needed on the frontend. Therefore, on the backend, we need to store it for later send it to the frontend.
Primary Key - (pk) field
In Django, the pk
field stands for "primary key." It's a special field that every record in a database table gets automatically. Its purpose is to give each record a unique identifier. For instance, if you have a table of products, each product will have its own pk
. Django handles this field automatically unless you specify another field for this purpose.
Thanks for your feedback!