How do transactions work in Django?
Django transactions group database operations so partial writes do not persist when an error happens mid-flow.
- Use transaction.atomic
- Good for multi-step writes
- Keep the transaction scope tight
Quick recall
Django transactions group database operations so partial writes do not persist when an error happens mid-flow.
Use relation-aware loading like select_related and prefetch_related when templates or loops will touch related objects repeatedly.
Authentication verifies who the user is, while authorization decides what that user is allowed to do.
select_related joins single-valued relations in SQL; prefetch_related fetches related collections in extra queries.
Cookies live in the browser, while sessions usually store server-side state and use a cookie only for the session key.
Static files are app assets you ship, while media files are user-uploaded content created after deployment.
Managers and custom QuerySet methods let you package reusable query logic close to the model layer.
A custom user model lets you control user fields and authentication structure instead of being locked into the default user shape.
collectstatic gathers static assets into one deployable location for serving in production.
CSRF protection ensures a state-changing request comes from your site and includes a valid token.
Migration squashing combines many historical migrations into a smaller set to reduce noise and startup cost.
Django admin gives a fast internal CRUD interface for managing data models without building custom screens first.