Home > Net >  Filter Data between two number Django
Filter Data between two number Django

Time:09-21

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

CodePudding user response:

You need to use gt and lt.

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

CodePudding user response:

You can use the model range to achieve that;

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

This should solve what you want to do.

CodePudding user response:

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

  • Related