I am making a real estate application in which I am stuck right now on a search functionality . My main problem is that I have to make a search function that can filter a query set based on the choices user chooses. And i am able to do it but the problem is there are two options that user can filter on and that's area and price and they both have min and max value so how I have to make a filter that can take both min and max values and then present the filter queryset which contains the objects that have values between the min and max.
Here's my search function
def search(request):
queryset = models.Property.objects.all()
query1 = request.GET.get('q1')
query2 = request.GET.get('q2')
query3 = request.GET.get('q3')
query4 = request.GET.get('q4')
query5 = request.GET.get('q5')
query6 = request.GET.get('q6')
if query:
queryset = queryset.filter(
Q(status__icontains=query)|
Q(address__icontains=query2)|
Q(rooms__icontains=query3)|
Q(bathroom__icontains=query4)|
Q(area__icontains=query5)|
Q(price__icontains=query6)
).all()
return render(request,'properties/properties_search_list.html',{'queryset':queryset})
Here's the area and price code in html
<div class="range-slider">
<label>Area</label>
<div data-min="0" data-max="10000" data-min-name="min_area" data-max-name="max_area" data-unit="Sq ft" class="range-slider-ui ui-slider" aria-disabled="false" name="q5" ></div>
<div class="clearfix"></div>
</div>
<div class="range-slider">
<label>Price</label>
<div data-min="0" data-max="150000" data-min-name="min_price" data-max-name="max_price" data-unit="USD" class="range-slider-ui ui-slider" aria-disabled="false" name="q6" ></div>
<div class="clearfix"></div>
</div>