Reputation: 4753
I've a Django model with a DecimalField
.
class SomeModel(models.Model):
decimal_field = models.DecimalField()
I'd like to get all model instances which have a field value in the range of e.g. 5.0
and 10.0
. I've read the Django docs section about queries but I did not find a solution. How do I have to write the query SomeModel.objects.filter(?)
?
Upvotes: 2
Views: 1411
Reputation: 21476
SomeModel.objects.filter(decimal_field__range=(lower_limit, upper_limit))
Upvotes: 3
Reputation: 675
You should use the __gt __gte __lt __lte field lookups, corresponding to greater, than greater than or equal, less than, less than or equal, so the query you want to do should look like:
SomeModel.objects.filter(decimal_field__gte=lower_limit, decimal_field__lte=upper_limit)
Upvotes: 2