我想用这样的过滤器查询我的 Django 模型:
(pseudo code)
field1values = ['val11','val12']
field2values = ['val21','val22']
result = (field1 == 'val11' | field1 == 'val12') & (field2 == 'val21' | field2 == 'val22')
如果我必须在这里只查询 field1,代码可能如下所示:
clauses = []
for item in field1values:
clauses.append(MyModel.objects.filter(field1=item))
result = reduce(lambda x, y: x | y, clauses)
但我不知道如何为我想要的复杂谓词创建过滤器