tags:

views:

99

answers:

2

Hello, 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 operator works fine (I'm using "|" )

Why is this so?

+1  A: 

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

John Mee
A: 

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

Yaroslav