Issue
I have a model Item
with field price
.
class Item(models.Model):
title = models.CharField(max_length=200, blank='true')
price = models.IntegerField(default=0)
My query may contain min_price
& max_price
values. So, my request may be like this: http://example.com/api/items?min_price=50&max_price=500
. Can anybody tell me, how can I query items between min & max values? Can I solve it using Django ORM?
Thanks!
Solution
Check api reference for range. Like it states
You can use range anywhere you can use BETWEEN in SQL — for dates, numbers and even characters.
So, in your case:
Item.objects.filter(price__range=(min_price, max_price))
Answered By - Yasel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.