This section covers the common operations used when creating models using the Django ORM. The table below lists the most common fields used in this process, and the table folowing it covers the common arguments used with the fields.
Please note that this is site provides the most commonly used django features. It is by no means intended to be an exhaustive documentation of the Django framework. You can always use the official django documentation by clicking the big green button below.
Django Models Docs| Model Field | Description | |
|---|---|---|
AutoField()
|
Used to create an id to create a primary key | |
BooleanField()
|
Used to create a boolean type data | |
CharField()
|
Used for 'shorter' string-type data | |
TextField()
|
Used for 'longer' string-type data | |
IntegerField()
|
Used for numbers of an integer type | |
DecimalField()
|
Used for numbers of a decimal type | |
DateTimeField()
|
Used to create datetime data | |
DateField()
|
Used to create a date field | |
DurationField()
|
Used for storing duration of time | |
EmailField()
|
Used for storing string data that is in a email format | |
FileField()
|
A field for uploading files | |
FilePathField()
|
Used for file path string type data | |
ForeignKey()
|
Used as a foreign key, and takes another model as the first argument | |
ImageField()
|
Used to upload an image (requires aditional library) |
| Model Field Opton | Functionality | |
|---|---|---|
primary_key
|
boolean - determines if a field is a primary key | |
foreign_key
|
boolean - determines if a field is a foreign key | |
default
|
any - sets a default value | |
null
|
boolean - determines if a field can have no value | |
blank
|
boolean - determines if a field can be left blank by user | |
max_length
|
integer - sets the max length of a charfield | |
max_digits
|
integer - sets the number of digits allowed before the decimal point | |
decimal_places
|
integer - sets the number of decimal places allows | |
auto_now_add
|
boolean - determins if a field should be added automatically upon creation | |
on_delete
|
function call - executes a function upon delete of a model instance |