假设我有这本词典
mydict['number'] = {23,24,25}
mydict['name'] = {"john","mike","kaff"}
mydict['area'] = {"london", "usa", "japan"}
我已经有了查询集qs
但是我想根据上面的内容进行额外的过滤,dictionary
例如
qs.filter (where number __icontains in 23,24,25)
等等qs.filter (where name __icontains in john, mike, kaff)
_
编辑:
这是我尝试过但很粗糙的
query_list = []
for key1 in mydict.iteritems():
for myval in mydict[key1]:
qry = qry + Q(myval__icontains= myval) |
query_list.append(qry)
queryset = Student.objects.filter(reduce(operator.and_, query_list))