Thank you so much it worked!! 

On Friday, 28 June 2019 20:27:23 UTC+5:45, jjmutumi wrote:
>
> Hello,
>
> I think it should work if you build the query sequentially. Like:
>
> def search(request):
> if request.method=='POST':
> srch = request.POST['srh']
> srchs = request.POST['gender']
>
> if srchs or srch:
> query = Snippet.objects
> if srch:
> query = query.filter(Q(name__istartswith=srch))
> if srchs:
> query = query.filter(Q(gender__iexact=srchs))
>
> if query.count() > 0:
> return render (request,'search.html',{'sr': query})
> else:
> messages.error(request,'no result found')
> return HttpResponse("<h1>No name found please Add names </h1>")
> else:
> return render(request,'search.html')
>
> return render(request,'search.html')
>
> On Friday, 28 June 2019 15:35:09 UTC+3, Surya Adhikari wrote:
>>
>> # my coding looks like this in views.py but somehow it only search by 
>> name no matter which gender i select .what am i doing wrong?
>>
>> def search(request):
>> if request.method=='POST':
>> srch = request.POST['srh'] 
>> srchs =  request.POST['gender']
>>
>> if srch and srchs:
>> match = Snippet.objects.filter(Q(name__istartswith=srch)) 
>> matchs = Snippet.objects.filter(Q(gender__iexact=srchs))
>>
>> if match and matchs:
>> return render (request,'search.html',{'sr':match})
>> #return render (request,'search.html',{'sr':match})
>> else:
>> messages.error(request,'no result found')
>> # return HttpResponse("<h1>No name found please Add names  </h1>")
>>
>> else:
>> # return HttpResponseRedirect('/search/')
>> return render(request,'search.html')
>>
>> return render(request,'search.html')
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/69c1dc32-037f-4303-8384-de35c34e53b3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to