Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Summary | Working with Database
Django: First Dive
course content

Course Content

Django: First Dive

Django: First Dive

1. Get Started
2. Write the First Page
3. Models
4. Working with Database
5. Templates
6. Request Handling

bookSummary

Now let's collect all the knowledge we have gained in one chapter.

Models

A Model is a class that represents a table from the database.

Model class structure

Model class should be inherited from the Model class.

The structure of the Model class should be filled in by Field objects.

Note

Some fields have non-optional parameters (arguments).

Manager

Manager allows tools to manipulate the data.

Command for Migrations

Note

Try the python3 if the python doesn't work.

Instances

To work with instances, you need to use different methods.

Create

  1. Create a new Model class instance.
  2. Fill in all necessary attributes.
  3. Submit changes using the save() method that send a query to the database.

Retrieve all

Return the iterable QuerySet containing database records.

Retrieve one

Return the one database record as the Model class instance.

Update

  1. Retrieve data.
  2. Reassign attributes of the Model class instance(s).
  3. Submit changes using the save() method that send a query to the database.

URL patterns

To receive the pk from the URL address, we need to use the specific syntax: <int:pk>, where:

  • int is a type of value;
  • pk is the name of the argument in the view function.

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 4. Chapter 5
some-alt