What is Model?
Model is a class that represents a table from a database. Attributes of a model class are attributes of a table in the database (columns or fields).
Instances of this class are records (data) in the database.
Consider the table below for a better understanding:
Look at the attributes of this table on the ER diagram.
The ER diagram represents the table structure. We can build this structure in the Django project using the Django ORM.
Note
Object Relation Mapping (ORM) is an interface for database manipulation.
The code of this table structure should look like this:
from django.db import models
class Product(models.Model):
name = models.CharField(max_length=100)
price = models.FloatField()
quantity = models.IntegerField()
Where:
Product
is a table name.name
,price
, andquantity
are attributes of theProduct
table.models
is a package with Django ORM tools.
Note
The
id
field is created automatically in Django. We will describe this later.
1. What is a Model?
2. What is an instance of the Model class?
3. What is Object Relation Mapping (ORM)?
Grazie per i tuoi commenti!
Chieda ad AI
Chieda ad AI
Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione
Awesome!
Completion rate improved to 3.45
What is Model?
Scorri per mostrare il menu
Model is a class that represents a table from a database. Attributes of a model class are attributes of a table in the database (columns or fields).
Instances of this class are records (data) in the database.
Consider the table below for a better understanding:
Look at the attributes of this table on the ER diagram.
The ER diagram represents the table structure. We can build this structure in the Django project using the Django ORM.
Note
Object Relation Mapping (ORM) is an interface for database manipulation.
The code of this table structure should look like this:
from django.db import models
class Product(models.Model):
name = models.CharField(max_length=100)
price = models.FloatField()
quantity = models.IntegerField()
Where:
Product
is a table name.name
,price
, andquantity
are attributes of theProduct
table.models
is a package with Django ORM tools.
Note
The
id
field is created automatically in Django. We will describe this later.
1. What is a Model?
2. What is an instance of the Model class?
3. What is Object Relation Mapping (ORM)?
Grazie per i tuoi commenti!