django/django
Data models
The framework itself defines no models. The contrib apps ship the only models in the django/ package; this page is the cheat sheet for what they are and how they relate.
django.contrib.auth
graph TD
User
Group
Permission
ContentType[("ContentType<br/>(contenttypes)")]
User -->|user_permissions M2M| Permission
User -->|groups M2M| Group
Group -->|permissions M2M| Permission
Permission -->|content_type FK| ContentType| Model | File | Notes |
|---|---|---|
AbstractBaseUser |
auth/base_user.py |
Minimum user shape |
AbstractUser |
auth/models.py |
Standard user (username, email, names, dates, permissions) |
User |
auth/models.py |
Concrete AbstractUser; the default AUTH_USER_MODEL |
Group |
auth/models.py |
Named bundle of Permission objects |
Permission |
auth/models.py |
(content_type, codename, name) tuple |
PermissionsMixin |
auth/models.py |
Adds is_superuser, groups, user_permissions |
AnonymousUser |
auth/models.py |
Singleton for unauthenticated requests; not stored in DB |
User.objects is a UserManager (auth/models.py) that exposes create_user(...) and create_superuser(...).
django.contrib.contenttypes
| Model | File | Notes |
|---|---|---|
ContentType |
contenttypes/models.py |
One row per installed model; (app_label, model) is unique |
GenericForeignKey |
contenttypes/fields.py |
A FK that points at any model via (content_type, object_id) |
GenericRelation |
contenttypes/fields.py |
Reverse relation accessor on the target side |
ContentType rows are seeded by a post_migrate signal handler. Each row maps to a Python Model class via ContentType.model_class().
django.contrib.sites
| Model | File | Notes |
|---|---|---|
Site |
sites/models.py |
(domain, name) for multi-site deployments |
SITE_ID is the active site identifier. request.site is set by CurrentSiteMiddleware.
django.contrib.sessions
| Model | File | Notes |
|---|---|---|
Session |
sessions/models.py |
The DB-backed session store; (session_key, session_data, expire_date) |
Other backends (cache, file, signed_cookies) don't use this model.
django.contrib.admin
| Model | File | Notes |
|---|---|---|
LogEntry |
admin/models.py |
Records every admin action: who, what, when, action_flag |
LogEntry.objects.log_action(...) is called by the change/add/delete views. The list of recent actions is shown on the admin home page.
django.contrib.flatpages
| Model | File | Notes |
|---|---|---|
FlatPage |
flatpages/models.py |
URL → HTML; M2M to Site |
The middleware (FlatpageFallbackMiddleware) intercepts 404s and serves a flatpage if one matches.
django.contrib.redirects
| Model | File | Notes |
|---|---|---|
Redirect |
redirects/models.py |
(site, old_path, new_path); FK to Site |
RedirectFallbackMiddleware intercepts 404s and redirects.
django.contrib.messages
messages doesn't define any models — messages are stored in the cookie or session backends.
django.contrib.staticfiles
staticfiles doesn't define any models — it's purely a collectstatic command and storage.
django.contrib.gis
GIS doesn't add new top-level models, but adds a number of geometry fields:
PointFieldLineStringFieldPolygonFieldMultiPointFieldMultiLineStringFieldMultiPolygonFieldGeometryFieldGeometryCollectionFieldRasterField
Plus the value types in django.contrib.gis.geos (GEOSGeometry, Point, LineString, Polygon, …) and django.contrib.gis.gdal (OGRGeometry, Layer, DataSource).
django.contrib.postgres
PostgreSQL-only fields:
ArrayField(any field type as elements).HStoreField(key-value map).RangeFieldand subclasses:IntegerRangeField,DecimalRangeField,DateRangeField,DateTimeRangeField.
Built-in field types (across all backends)
These are not contrib — they live at django/db/models/fields/ and are the public ORM API.
| Field | File | Notes |
|---|---|---|
AutoField |
__init__.py |
Auto-incrementing integer PK |
BigAutoField, SmallAutoField |
__init__.py |
64- and 16-bit variants |
CharField |
__init__.py |
Variable-length text with max_length |
TextField |
__init__.py |
Unbounded text |
IntegerField, BigIntegerField, SmallIntegerField, PositiveIntegerField, PositiveSmallIntegerField, PositiveBigIntegerField |
__init__.py |
Integer variants |
BooleanField |
__init__.py |
|
DateField, DateTimeField, TimeField |
__init__.py |
|
DurationField |
__init__.py |
timedelta |
DecimalField |
__init__.py |
Fixed-precision decimal |
FloatField |
__init__.py |
|
EmailField, URLField, SlugField |
__init__.py |
CharField subclasses with validators |
UUIDField |
__init__.py |
|
IPAddressField, GenericIPAddressField |
__init__.py |
|
BinaryField |
__init__.py |
bytes |
JSONField |
json.py |
All-backend JSON |
FileField, ImageField, FilePathField |
files.py |
Files on disk |
GeneratedField |
generated.py |
Database-side computed columns |
ForeignKey, OneToOneField, ManyToManyField |
related.py |
Relationships |
CompositePrimaryKey |
composite.py |
Multi-column PK (added in 5.2) |
Where to read the source
django/db/models/fields/__init__.py— most field types.django/db/models/fields/related.py— relations.django/db/models/fields/json.py—JSONField.django/db/models/fields/files.py—FileField,ImageField.django/db/models/fields/generated.py—GeneratedField.django/db/models/fields/composite.py—CompositePrimaryKey.django/contrib/auth/models.py— auth models.django/contrib/contenttypes/models.py— ContentType.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.