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")
queryset2 = Item.objects.filter(color="white")
queryset1 & queryset2
gives me the empty set []
|
" )
Why is this so?
qs = Item.objects.filter(color__in=['blue','white'])
Item.objects.filter(color="blue").filter(color="white")
精彩评论