Model examples
These examples are from Django version 0.95. For current documentation, go here.
This is a set of example models.
- Bare-bones model
- Adding __str__() to models
- Giving models custom methods
- Many-to-one relationships
- Many-to-many relationships
- Specifying ordering
- The lookup API
- get_latest_by
- Many-to-many relationships via an intermediary table
- One-to-one relationships
- Relating an object to itself, many-to-one
- Relating a model to another model more than once
- Adding hooks before/after saving and deleting
- Using a custom primary key
- Transactions
- Many-to-one relationships that can be null
- Custom column names
- Using SQL reserved names
- OR lookups
- Multiple many-to-many relationships between the same two tables
- Specifying 'choices' for a field
- Using properties on models
- Giving models a custom manager
- Mutually referential many-to-one relationships
- Reverse lookups
- Invalid models
- Default manipulators
- Many-to-many relationships between the same two tables
- Many-to-many and many-to-one relationships to the same table
- Object pagination
- Validation
- Callable defaults
- get_or_create()
- Generic relations

