Django ORM等效于MySql多列IN子句

时间:2014-05-05 06:34:32

标签: mysql django django-models

有没有办法使用Django ORM进行以下查询?

SELECT * FROM table1 WHERE (x, y) IN ((1, 'a'), (2, 'b'))

1 个答案:

答案 0 :(得分:0)

Q对象怎么样?

query = reduce(operator.or_, [Q(x=d[0], y=d[1]) for d in [(1, 'a'), (2, 'b')]]

Table1.objects.filter(query)