7.11. ORM F

>>> from django.db.models import F
>>>
>>> Customer.objects.all().update(age=F('age')+1)

7.11.1. Filters can reference fields on the model

from django.db.models import F

Entry.objects.filter(n_comments__gt=F('n_pingbacks'))
Entry.objects.filter(n_comments__gt=F('n_pingbacks') * 2)
Entry.objects.filter(rating__lt=F('n_comments') + F('n_pingbacks'))
Entry.objects.filter(authors__name=F('blog__name'))
from datetime import timedelta

Entry.objects.filter(mod_date__gt=F('pub_date') + timedelta(days=3))

7.11.2. F() expressions

An F() object represents the value of a model field or annotated column. It makes it possible to refer to model field values and perform database operations using them without actually having to pull them out of the database into Python memory.

Iris.objects.all().update(petal_length=F('petal_length') + 1)