Issue
I have a User
model with age
property
my models.py
class User(models.Model):
age = models.IntegerField()
i need to output all users between age 25 and 35
i can only make query which won't exclude others users
first_query = User.objects.filter(age__gte=25)
second_query = User.objects.filter(age__lte=35)
can i output users between age 25 and 35 and exclude others
, in one query?
Solution
Try this:
User.objects.filter(age__gte=25, age__lte=35)
https://docs.djangoproject.com/en/4.0/ref/models/querysets/#gte
https://docs.djangoproject.com/en/4.0/ref/models/querysets/#lte
Answered By - rahul.m
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.