开发者

Intersection of two querysets in django

I can't do an AND on two querysets. As in, q1 & q2. I get the empty set and I do not know why. I have tested this with the simplest cases. I am using django 1.1.1

I have basically objects like this:

item1
   name="Joe"
   color = "blue"
item2
   name="Jim"
   color = "blue"
   color = "white"
item3
   name="John"
   color = "red"
   color = "white"

Is there something weird about having a many-to-many relationship or what am I missing?

queryset1 = Item.objects.filter(color="blue")

this gives (item1, item2)

queryset2 = Item.objects.filter(color="white")

this gives (item2, item3)

queryset1 & queryset2 gives me the empty set []

The OR 开发者_StackOverflow社区operator works fine (I'm using "|" )

Why is this so?


qs = Item.objects.filter(color__in=['blue','white'])


Item.objects.filter(color="blue").filter(color="white")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜