Models
A model is the single, definitive source of information about your data. It contains the essential fields and behaviors of the data you're storing. Generally, each model maps to a single database table.
The basics:
- Each model is a Python class that subclasses django.db.models.Model.
- Each attribute of the model represents a database field.
-
With all of this, Django gives you an automatically-generated database-access API; see Making queries.
Quick example
Using models
Fields
Field types
Field options
Automatic primary key fields
Verbose field names
Relationships
Many-to-one relationships
Many-to-many relationships
Extra fields on many-to-many relationships
One-to-one relationships
Models across files
Field name restrictions
Custom field types
Meta options
Model methods
Overriding predefined model methods
Overriding predefined model methods
Executing custom SQL
Model inheritance
Abstract base classes
Meta inheritance
Be careful with related_name
Multi-table inheritance
Meta and multi-table inheritance
Proxy models
Base class restrictions
Multiple inheritance
Field name "hiding" is not permitted