Reputation: 912
I am trying to figure out the difference between the __lte and __gte in Django.
The reason being that I am trying to create a function with dates that can work only with a time frame, so I've been researching between Field Lookups Comparison.
I've looked up several documentations https://docs.djangoproject.com/en/3.0/ref/models/querysets/#exclude
but didn't reach a conclusive answer.
Edited:
I learned that lte is less than or equal and gte greater than or equal
Here is some documentation link
Upvotes: 10
Views: 47811
Reputation: 477437
The __lte
lookup [Django-doc] means that you constrain the field that is should be less than or equal to the given value, whereas the __gte
lookup [Django-doc] means that the field is greater than or equal to the given value.
So for example:
MyModel.objects.filter(field__gte=5) # field ≥ 5
MyModel.objects.filter(field__lte=5) # field ≤ 5
Upvotes: 8
Reputation: 1
The __lte lookup [Django-doc] means that you constrain the field that is should be less than or equal to the given value, whereas the __gte lookup [Django-doc] means that the field is greater than or equal to the given value.
Upvotes: 0
Reputation: 2277
according to https://docs.djangoproject.com/en/dev/ref/models/querysets/
__lte -> Less than or equal
__gte -> Greater than or equal
__lt -> Less than
__gt -> Greater than
QuerySet(foo__lte=10) # foo <= 10
QuerySet(foo__gte=10) # foo >= 10
QuerySet(foo__lt=10) # foo < 10
QuerySet(foo__gt=10) # foo > 10
Upvotes: 28
Reputation: 10237
gte stands for 'greater than or equal', lte stands for 'lower than or equal' accordingly
Upvotes: 2