Useful Links
Computer Science
Web Development
Django Framework
1. Introduction to Django
2. Getting Started
3. Models: The Data Layer
4. Views: The Logic Layer
5. Templates: The Presentation Layer
6. URL Routing
7. Forms
8. The Django Admin
9. Static and Media Files
10. Authentication and Authorization
11. Testing
12. Security
13. Advanced Topics
14. Deployment
15. Extending Django
Models: The Data Layer
Defining Models
The `models.Model` Class
Creating a Model Class
Model Class Naming Conventions
Model Docstrings and Meta Information
Fields
Common Field Types
`CharField`
`TextField`
`IntegerField`
`FloatField`
`BooleanField`
`DateField`
`DateTimeField`
`EmailField`
`FileField`
`ImageField`
`URLField`
`SlugField`
`DecimalField`
`PositiveIntegerField`
`BigIntegerField`
`TimeField`
`DurationField`
`UUIDField`
`JSONField`
Field Options
`null`
`blank`
`default`
`unique`
`primary_key`
`verbose_name`
`choices`
`help_text`
`editable`
`max_length`
`max_digits`
`decimal_places`
`upload_to`
`db_index`
`db_column`
Relationships
Foreign Keys (`ForeignKey`)
Defining Foreign Keys
Related Name and Related Query Name
On Delete Behaviors
`CASCADE`
`PROTECT`
`SET_NULL`
`SET_DEFAULT`
`SET()`
`DO_NOTHING`
Many-to-Many Relationships (`ManyToManyField`)
Defining Many-to-Many Fields
Through Models
Symmetrical Relationships
Related Name in Many-to-Many
One-to-One Relationships (`OneToOneField`)
Use Cases for One-to-One
Defining One-to-One Fields
Parent Link Fields
Migrations
Creating Migrations with `makemigrations`
Automatic Migration Detection
Naming Migrations
Empty Migrations
Applying Migrations with `migrate`
Forward Migrations
Fake Migrations
Understanding Migration Files
Migration File Structure
Dependencies and Operations
Migration Operations
`CreateModel`
`DeleteModel`
`AddField`
`RemoveField`
`AlterField`
`RenameField`
`RunSQL`
`RunPython`
Inspecting SQL with `sqlmigrate`
Rolling Back Migrations
Unapplying Migrations
Migration History
Managing Migration Conflicts
Merge Migrations
Squashing Migrations
Data Migrations
Creating Data Migrations
Writing Migration Functions
The Django ORM (Object-Relational Mapper)
QuerySets
Definition and Characteristics
Lazy Evaluation
QuerySet Caching
Evaluating QuerySets
Creating Objects
Using `create()`
Using `save()`
Using `get_or_create()`
Using `update_or_create()`
Bulk Creation with `bulk_create()`
Retrieving Objects
Using `all()`
Using `get()`
Using `filter()`
Using `exclude()`
Using `first()` and `last()`
Using `order_by()`
Using `distinct()`
Using `values()` and `values_list()`
Using `only()` and `defer()`
Using `select_related()`
Using `prefetch_related()`
Updating Objects
Modifying Fields and Saving
Using `update()`
Bulk Updates with `bulk_update()`
Deleting Objects
Using `delete()`
Cascading Deletes
Soft Deletes
Advanced Querying
Field Lookups
`exact`
`iexact`
`contains`
`icontains`
`startswith`
`endswith`
`in`
`gt`
`gte`
`lt`
`lte`
`range`
`isnull`
`regex`
`iregex`
Chaining Filters
Q Objects for Complex Lookups
Combining Queries with Q
Negating Queries
OR and AND Operations
F Expressions for Field References
Field-to-Field Comparisons
Avoiding Race Conditions
Mathematical Operations
Aggregation
Using `Count`
Using `Sum`
Using `Avg`
Using `Min` and `Max`
Using `StdDev` and `Variance`
Annotation
Adding Calculated Fields to QuerySets
Conditional Annotations with `Case` and `When`
Subqueries
Using `Subquery`
Using `OuterRef`
Using `Exists`
Raw SQL Queries
Using `raw()`
Using `extra()`
Direct Database Connections
Model Managers
Default Manager
Overriding the Default Manager
Creating Custom Manager Methods
Using Managers in Queries
Manager Inheritance
Model Methods
Instance Methods
Class Methods
Static Methods
The `str()` Method
The `get_absolute_url()` Method
Custom Save and Delete Methods
Model Meta Options
`ordering`
`verbose_name`
`verbose_name_plural`
`db_table`
`unique_together`
`index_together`
`permissions`
`abstract`
`proxy`
`managed`
`default_permissions`
`get_latest_by`
`indexes`
`constraints`
Previous
2. Getting Started
Go to top
Next
4. Views: The Logic Layer