509π
β
Greater than:
Person.objects.filter(age__gt=20)
Greater than or equal to:
Person.objects.filter(age__gte=20)
Less than:
Person.objects.filter(age__lt=20)
Less than or equal to:
Person.objects.filter(age__lte=20)
You can find them all in [the documentation].(https://docs.djangoproject.com/en/stable/ref/models/querysets/).
π€lprsd
0π
Put __gt suffix for "Greater Than" to the field name age
:
Person.objects.filter(age__gt=20)
# ββββ
# age > 20
Put __gte suffix for "Greater Than or Equal to" to the field name age
:
Person.objects.filter(age__gte=20)
# βββββ
# age >= 20
Put __lt suffix for "Less Than" to the field name age
:
Person.objects.filter(age__lt=20)
# ββββ
# age < 20
Put __lte suffix for "Less Than or Equal to" to the field name age
:
Person.objects.filter(age__lte=20)
# βββββ
# age <= 20
- [Django]-Combining Django F, Value and a dict to annotate a queryset
- [Django]-Django storages: Import Error β no module named storages
- [Django]-Django-tables2: How to use accessor to bring in foreign columns?
Source:stackexchange.com