python - How can i do the Q filter search based on dictionary and its keys in Django -


suppose have dictionary

mydict['number'] = {23,24,25} mydict['name'] = {"john","mike","kaff"} mydict['area'] = {"london", "usa", "japan"} 

i have query set qs

but want have additional filtering based on above dictionary like

qs.filter (where number __icontains in 23,24,25)

and qs.filter (where name __icontains in john, mike, kaff) , on

edit:

this have tried rough

query_list = []  key1 in mydict.iteritems():   myval in  mydict[key1]:     qry = qry + q(myval__icontains= myval) | query_list.append(qry)  queryset = student.objects.filter(reduce(operator.and_, query_list)) 

i combine argument filter q objects. https://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -