Re: Multiple conditions on same field in JOIN over three models

2010-12-17 Thread Jonas H.
On 12/17/2010 08:38 PM, Łukasz Rekucki wrote: Blog.objects.filter(post_tags__name__in=["foo", "bar"]).annotate(match_count=Count('post__tags')).filter(match_count=2) This should give you the right results. Neat! And blazingly fast, too, I guess! Thank you very much, anyway :-) Jonas -- You

Re: Multiple conditions on same field in JOIN over three models

2010-12-17 Thread Łukasz Rekucki
On 17 December 2010 19:20, Jonas H. wrote: > Hello! > > Assuming the following data model: > > +--+                +--+                   +-+ > | Blog | has many (1:n) | Post | tagged with (n:m) | Tag | > +--+                +--+                   +-+ > > I want to filter o

Re: Multiple conditions on same field in JOIN over three models

2010-12-17 Thread Jonas H.
On 12/17/2010 08:21 PM, Javier Guerra Giraldez wrote: Blog.objects.filter(post__tags__name="foo").filter(post__tags__name="bar") That's "get all blogs that have at least one post tagged with 'foo' and one post tagged with 'bar'", not requiring that *one post* matches *both* conditions. -- Y

Re: Multiple conditions on same field in JOIN over three models

2010-12-17 Thread Javier Guerra Giraldez
On Fri, Dec 17, 2010 at 1:20 PM, Jonas H. wrote: > Blog.objects.filter(post__tags__name="foo", >                        post__tags__name="bar") untested: Blog.objects.filter(post__tags__name="foo").filter(post__tags__name="bar") -- Javier -- You received this message because you are subscrib

Multiple conditions on same field in JOIN over three models

2010-12-17 Thread Jonas H.
Hello! Assuming the following data model: +--++--+ +-+ | Blog | has many (1:n) | Post | tagged with (n:m) | Tag | +--++--+ +-+ I want to filter out all blogs that have a post tagged with "foo" and "bar"