The intersection of two queries in django

I am unable to AND on two queries. As in, q1 and q2. I am getting an empty set and I don't know why. I 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 anything weird about the many-to-many relationship or what I am missing?

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


this gives (item1, item2)

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


this gives (item2, item3)

queryset1 & queryset2

gives an empty set []


OR operator works fine (I use " |

")

Why is this so?

+2


a source to share


2 answers


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

      



+3


a source


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

      



+1


a source







All Articles