Intersection of two querysets in django
Posted
by unagimiyagi
on Stack Overflow
See other posts from Stack Overflow
or by unagimiyagi
Published on 2010-04-27T06:22:24Z
Indexed on
2010/04/27
8:23 UTC
Read the original article
Hit count: 317
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?
© Stack Overflow or respective owner