Contenido del Curso
Django: First Dive
Django: First Dive
Summary
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).
Command for Migrations
Note
Try the
python3
if thepython
doesn't work.
Instances
To work with instances, you need to use different methods.
Create
- Create a new Model class instance.
- Fill in all necessary attributes.
- Submit changes using the
save()
method that send a query to the database.
Retrieve one
Return the one database record as the Model class instance.
Update
- Retrieve data.
- Reassign attributes of the Model class instance(s).
- 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.
¡Gracias por tus comentarios!