On Wed, Apr 28, 2010 at 1:00 AM, HWM-Rocker <olafgla...@gmail.com> wrote:
> I have a TaggedObject that has a GenericRelation to Foo with the name
> tags. When I am searching something like that
>
> TaggedObject.objects.filter(Q(tags__tag=1)&Q(tags__tag=4))
>
> I get no Objects in return. But when I filter with (or) '|' then I get
> 4 Objects. But I have only 3 objects tagged. So the object, that was
> tagged with 1 and with 4 will be returned twice?
>
> Thats strange. Any idea how to create this queries correctly?
>
> thanks in advance!!!
>

That query looks for tags which are both 1 and 4 at the same time.
What you want to do is look for tags which are 1, look for tags which
are 4, and intersect them.

In other words:

TaggedObject.objects.filter(tags__tag=1).filter(tags__tag=4)


Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to