python - Django Query lookup using Q Not Returning the Right Result -


i want basic query search. want use fields city , area perform datatbase lookup.

i want case whereby if user input city , area in search field, should return results. if user input either city or area should return result.

the below code didn't return result when input city , area in search field, , have objects related query saved in database. instead returns 'no result'.

def my_search(request):     try:         q= request.get['q']         hots= place.objects.filter(q(city__icontains=q)&q(area__icontains=q))         c_hos=hots.count()         return render(request, 'search/own_search.html',{'hots':hots, 'q':q, 'c_hos':c_hos})      except keyerror:          return render(request, 'search/own_search.html') 

i tried using | , won't return result when input city , area in field.

what missing?

you should go or operator "|" if want accept query of city or area only. suggest print variable q after being taken request see in , database query again. thought maybe should split value of q city , area.


Comments