Skip to content
Advertisement

Difference between the __lte and __gte in Django

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

Advertisement

Answer

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
Advertisement