0PricingLogin
Django Academy · Lesson

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 F

All lessons in this course

  1. aggregate vs annotate
  2. F Expressions for Atomic Updates
  3. Q Objects for Complex Filters
  4. Conditional Aggregation with Case/When
← Back to Django Academy