我不能对两个查询集执行 AND。如 q1 和 q2。我得到空集,我不知道为什么。我已经用最简单的案例对此进行了测试。我正在使用 Django 1.1.1
我基本上有这样的对象:
item1
name="Joe"
color = "blue"
item2
name="Jim"
color = "blue"
color = "white"
item3
name="John"
color = "red"
color = "white"
建立多对多关系有什么奇怪的地方吗?或者我错过了什么?
queryset1 = Item.objects.filter(color="blue")
这给出了 (item1, item2)
queryset2 = Item.objects.filter(color="white")
这给出了 (item2, item3)
queryset1 & queryset2 给我空集 []
OR 运算符工作正常(我正在使用 "|")
为什么会这样?
请您参考如下方法:
qs = Item.objects.filter(color__in=['blue','white'])
