[Solved]-How to do less than or equal to and greater than equal to in django filter?

24👍

Why don’t you use the _range function?

filter(gender='MALE', age__range=(10, 50))

See here:
https://docs.djangoproject.com/en/1.7/ref/models/querysets/#range

Edit for new link:
https://docs.djangoproject.com/en/3.0/ref/models/querysets/#range

👤mikeb

22👍

If you really want to use >= and <= yo could write:

Modelname.objects.filter(gender='MALE', age__gte = 10, age__lte = 50).count()
👤doru

Leave a comment