EDIT: 
the query should be:

Book.objects.values('rating').annotate(books_per_rating=Count('id')).aggregate(Max('books_per_rating'))

*books_per_rating* should be quoted in *Max* call.

On Friday, July 19, 2013 11:49:52 AM UTC+5:30, Debanshu Kundu wrote:
>
> If I have a model *Book* defined as:
>
> class Book(models.Model):
>    name = models.CharField(max_length=300)
>    pages = models.IntegerField()
>    price = models.DecimalField(max_digits=10, decimal_places=2)
>    rating = models.FloatField()
>    pubdate = models.DateField()
>
> and I run the query:
>
> Book.objects.values('rating').annotate(books_per_rating=Count('id')).aggregate(Max(books_per_rating))
>
> I get a *DatabaseError*.
>
> According to this 
> https://docs.djangoproject.com/en/1.5/topics/db/aggregation/#aggregating-annotations,
>  
> Django supports aggregating annotations. But in the example given in the 
> link itself, they annotate over a *QuerySet* which in turn returns a *
> QuerySet* (and not *ValuesQuerySet*), so aggregate method runs 
> successfully. But in my example aggregating a *ValuesQuerySet* raises a *
> DatabaseError*.
>
> Is it a bug in Django? Because if Django does not support aggregation over 
> *ValuesQuerySet* then it should raise an exception at Django level (not *
> DatabaseError*).
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to