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
Post a Comment