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
22👍
If you really want to use >=
and <=
yo could write:
Modelname.objects.filter(gender='MALE', age__gte = 10, age__lte = 50).count()
👤doru
- Failed: Database access not allowed, use the "django_db" mark, or the "db" or "transactional_db" fixtures to enable it
- Project management/build tools for a Django project?
- Get foreign key objects in a single query
- How can I send e-mail from django using the google smtp server?
- How to test a model that has a foreign key in django?
Source:stackexchange.com