我需要过滤这样的事情:
(status = 0 OR status = 4) OR (parameter = NONE AND status = 1)
如何将其转换为django查询集?
可能的解决方案
尝试1:
obj.filter(Q(status=0) | Q(status=4) | (Q(par=None) & Q(status = 1)))
Real query:
it = it.filter( (Q(respond_status=0) | Q(respond_status=4)) | (Q(respond_status=1) & Q(plant__isnull=True) ))
^
SyntaxError: invalid syntax
尝试2:
obj_total = []
for obj in objs:
if (obj.status == 0 or obj.status == 4) or (obj.status == 0 and obj.param == None):
obj_total.append(obj)
objs = Obj.objects.filter(id__in=[x.id for x in obj_total])
这实际上效率低下