On Jan 20, 1:36 am, Russell Keith-Magee <freakboy3...@gmail.com>
wrote:
> On Wed, Jan 20, 2010 at 3:42 AM, Collin Anderson
>
> <collinmander...@gmail.com> wrote:
> > Is there anyway to have the filter only apply to the annotation, so it
> > would return all publishers, with some having a num_books=0?
>
> If I understand your request correctly, I think this falls into the
> category of annoyingly simple query that is hard to express in SQL -

> Yours,
> Russ Magee %-)

I don't know if I'm understanding this differently, or if what I'm
about to suggest is exactly what you're saying won't work (its
untested), but I'd my interpretation of you question is you want all
publishers that have a book rating greater than 3, plus publishers
that have no books. So the only ones excluded would have a book rating
less than 3? I was thinking with Q objects:

Publisher.objects.annotate(num_books=Count('book')).filter(Q
(book__rating__gt=3.0) | Q(num_books=0))

I have a sneaking suspicion this won't work though....

Peter
-- 
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