Fixed #28233 -- Used a simpler example in the aggregation "cheat sheet" docs.

This commit is contained in:
Tim Graham 2017-06-06 16:11:48 -04:00
parent 525dc283a6
commit 49b9c89d40
1 changed files with 5 additions and 5 deletions

View File

@ -67,11 +67,11 @@ In a hurry? Here's how to do common aggregate queries, assuming the models above
>>> Book.objects.all().aggregate(Max('price')) >>> Book.objects.all().aggregate(Max('price'))
{'price__max': Decimal('81.20')} {'price__max': Decimal('81.20')}
# Cost per page # Difference between the highest priced book and the average price of all books.
>>> from django.db.models import F, FloatField, Sum >>> from django.db.models import FloatField
>>> Book.objects.all().aggregate( >>> Book.objects.aggregate(
... price_per_page=Sum(F('price')/F('pages'), output_field=FloatField())) ... price_diff=Max('price', output_field=FloatField()) - Avg('price')))
{'price_per_page': 0.4470664529184653} {'price_diff': 46.85}
# All the following queries involve traversing the Book<->Publisher # All the following queries involve traversing the Book<->Publisher
# foreign key relationship backwards. # foreign key relationship backwards.