Bambier
Bambier

Reputation: 846

Filter Data between two number Django

How can I filter my model obj in range of numbers some thing like

Item.objects.filter(4500< price < 7500)

I try for loop but its too slow and take lots of sources

Upvotes: 0

Views: 124

Answers (3)

Rayhan Hossen
Rayhan Hossen

Reputation: 26

You can use range filter

Item.objects.filter(price__range=(4500, 7500))

For better understanding check the ref link : - https://docs.djangoproject.com/en/3.2/ref/models/querysets/#range

Upvotes: 1

samkayz
samkayz

Reputation: 97

You can use the model range to achieve that;

Model.objects.filter(price__range=[frm, to])

This should solve what you want to do.

Upvotes: 1

kamran890
kamran890

Reputation: 842

You need to use gt and lt.

Item.objects.filter(price__gt=4500, price__lt=7500)

Upvotes: 2

Related Questions