Re: Need help on a (maybe complex) query with aggregate/annotate

2012-02-22 Thread Enrico
Works like a charm. Thanks! Ciao Enrico On Feb 21, 11:06 pm, Michael Elkins wrote: > On Tue, Feb 21, 2012 at 01:10:28PM -0800, Enrico wrote: > >But your query counts all the books, even the bad ones. I only need to > >count the good ones... > > >For example, if my books are: > > >1. name: LOTR,

Re: Need help on a (maybe complex) query with aggregate/annotate

2012-02-21 Thread Michael Elkins
On Tue, Feb 21, 2012 at 01:10:28PM -0800, Enrico wrote: But your query counts all the books, even the bad ones. I only need to count the good ones... For example, if my books are: 1. name: LOTR, rating: 10, publisher: A ... 2. name: ASOIAF, rating: 10, publisher: A ... 3. name: Twilight, rating

Re: Need help on a (maybe complex) query with aggregate/annotate

2012-02-21 Thread Enrico
Thanks Micheal for the response! But your query counts all the books, even the bad ones. I only need to count the good ones... For example, if my books are: 1. name: LOTR, rating: 10, publisher: A ... 2. name: ASOIAF, rating: 10, publisher: A ... 3. name: Twilight, rating 1, publisher: B ... an

Re: Need help on a (maybe complex) query with aggregate/annotate

2012-02-21 Thread Michael Elkins
On Feb 21, 6:11 am, Enrico wrote: > This query: > Publisher.objects.filter(book__rating__gt=3.0).annotate(num_books=Count('bo > ok')) > returns all the publishers with at least one good book (ranked > 3) > with annotated the number of good books for each publisher. > > How can i modify the query

Need help on a (maybe complex) query with aggregate/annotate

2012-02-21 Thread Enrico
I'm having a bit of hard time with aggregation. For simplicity's sake consider the models available in the aggregation docs: https://docs.djangoproject.com/en/1.3/topics/db/aggregation/# This query: Publisher.objects.filter(book__rating__gt=3.0).annotate(num_books=Count('book')) returns all the p