summaryrefslogtreecommitdiff
path: root/docs/topics/db/aggregation.txt
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-10-25 12:27:27 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-10-25 12:27:56 +0200
commit415ef34c4c2d4e9416ecf04ddf8cfb33585f1934 (patch)
tree12194fbcd557df1cd3ea5099307da032ad360812 /docs/topics/db/aggregation.txt
parent8b18e0bb3ba8bb1f51e15487a6d5402853e637ae (diff)
[5.0.x] Added missing pycon directives in various docs.
Backport of 718b32c6918037cfc746d7867333d79a3c887a8c from main
Diffstat (limited to 'docs/topics/db/aggregation.txt')
-rw-r--r--docs/topics/db/aggregation.txt14
1 files changed, 11 insertions, 3 deletions
diff --git a/docs/topics/db/aggregation.txt b/docs/topics/db/aggregation.txt
index 9f98504c0c..cd53f73c74 100644
--- a/docs/topics/db/aggregation.txt
+++ b/docs/topics/db/aggregation.txt
@@ -222,12 +222,14 @@ Combining multiple aggregations
Combining multiple aggregations with ``annotate()`` will :ticket:`yield the
wrong results <10060>` because joins are used instead of subqueries:
+.. code-block:: pycon
+
>>> book = Book.objects.first()
>>> book.authors.count()
2
>>> book.store_set.count()
3
- >>> q = Book.objects.annotate(Count('authors'), Count('store'))
+ >>> q = Book.objects.annotate(Count("authors"), Count("store"))
>>> q[0].authors__count
6
>>> q[0].store__count
@@ -237,7 +239,11 @@ For most aggregates, there is no way to avoid this problem, however, the
:class:`~django.db.models.Count` aggregate has a ``distinct`` parameter that
may help:
- >>> q = Book.objects.annotate(Count('authors', distinct=True), Count('store', distinct=True))
+.. code-block:: pycon
+
+ >>> q = Book.objects.annotate(
+ ... Count("authors", distinct=True), Count("store", distinct=True)
+ ... )
>>> q[0].authors__count
2
>>> q[0].store__count
@@ -514,7 +520,9 @@ the annotation is computed over all members of the group.
For example, consider an author query that attempts to find out the average
rating of books written by each author:
- >>> Author.objects.annotate(average_rating=Avg('book__rating'))
+.. code-block:: pycon
+
+ >>> Author.objects.annotate(average_rating=Avg("book__rating"))
This will return one result for each author in the database, annotated with
their average book rating.