Model examples
These examples are from Django's SVN release, which can be significantly different from previous releases. Get old examples here: 0.96, 0.95.
This is a set of example 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
- Transactions
- Many-to-one relationships that can be null
- Custom column/table 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
- Many-to-many relationships between the same two tables
- Many-to-many and many-to-one relationships to the same table
- Object pagination
- Callable defaults
- get_or_create()
- Generic relations
- DB-API Shortcuts
- Fixtures.
- User-registered management commands
- Empty model tests
- Tests for select_related()
- Storing files according to a custom storage system

