With = below, I could filter persons by age:
qs = Person.objects.filter(age = 20)
# ↑ Here
But with >, <, >= and <= below, I couldn’t filter persons by age:
qs = Person.objects.filter(age > 20)
# ↑ Here
qs = Person.objects.filter(age < 20)
# ↑ Here
qs = Person.objects.filter(age >= 20)
# ↑↑ Here
qs = Person.objects.filter(age <= 20)
# ↑↑ Here
Then, I got the error below:
NameError: name ‘age’ is not defined
How can I do greater than(>), greater than or equal to(>=), less than(<) and less than or equal to(>=) with filter() in Django?
Greater than:
Greater than or equal to:
Less than:
Less than or equal to:
You can find them all in [the documentation].(https://docs.djangoproject.com/en/stable/ref/models/querysets/).