F Expressions for Atomic Updates
Update columns using their own values safely.
The Read-Modify-Write Trap
Loading a value, changing it in Python, then saving creates a race: two requests can read the same number and overwrite each other.
Enter F Expressions
An F expression refers to a column by name, letting the database do the math itself instead of round-tripping the value to Python.
from django.db.models import FAll lessons in this course
- aggregate vs annotate
- F Expressions for Atomic Updates
- Q Objects for Complex Filters
- Conditional Aggregation with Case/When