Re: Aggregating annotations
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=30and I run the query:0 ) pages = models.IntegerField() price = models.DecimalField(max_digits= 10, decimal_places=2) rating = models.FloatField() pubdate = models.DateField()Book.objects.values('rating').
I get a DatabaseError.annotate(books_per_rating= Count('id')).aggregate(Max( books_per_rating)) According to this https://docs.djangoproject.com/en/1.5/ , 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.topics/db/aggregation/# aggregating-annotations 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+unsubscribe@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.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home