Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Overview of Models | What is Serialization?
Django REST Framework

Overview of ModelsOverview 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

shop

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.

AppFolder\models.py
Code Description
The Product model includes the following fields:

name: A character field with a maximum length of 255 characters, storing the name of the product.

description: A text field for storing a detailed description of the product.

price: A decimal field with a maximum of 10 digits, including 2 decimal places, representing the price of the product.

quantity_available: An integer field with a default value of 0, indicating the quantity of the product available in stock.

image: A character field with a maximum length of 255 characters, allowing for the storage of a file path or URL for the product's image.

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.

Don't forget to make and run migrations.

What role do models play in a Django REST Framework (DRF) application?

Виберіть правильну відповідь

Все було зрозуміло?

Секція 2. Розділ 2
course content

Зміст курсу

Django REST Framework

Overview of ModelsOverview 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

shop

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.

AppFolder\models.py
Code Description
The Product model includes the following fields:

name: A character field with a maximum length of 255 characters, storing the name of the product.

description: A text field for storing a detailed description of the product.

price: A decimal field with a maximum of 10 digits, including 2 decimal places, representing the price of the product.

quantity_available: An integer field with a default value of 0, indicating the quantity of the product available in stock.

image: A character field with a maximum length of 255 characters, allowing for the storage of a file path or URL for the product's image.

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.

Don't forget to make and run migrations.

What role do models play in a Django REST Framework (DRF) application?

Виберіть правильну відповідь

Все було зрозуміло?

Секція 2. Розділ 2
some-alt