summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorsdolemelipone <mark.gensler@protonmail.com>2022-12-03 11:14:57 +0000
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-12-05 05:19:23 +0100
commit344593893b6fc5fdda45a74013fc8622401c5058 (patch)
tree81c1dcbd39348338158a221e2c27193b57ce7477 /docs
parent0abd8f1cb8a9bab4627f5798ff5a87c32926b562 (diff)
Fixed #34199 -- Added example to StringAgg docs.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/contrib/postgres/aggregates.txt26
1 files changed, 26 insertions, 0 deletions
diff --git a/docs/ref/contrib/postgres/aggregates.txt b/docs/ref/contrib/postgres/aggregates.txt
index d8964115e0..55ec952fa2 100644
--- a/docs/ref/contrib/postgres/aggregates.txt
+++ b/docs/ref/contrib/postgres/aggregates.txt
@@ -208,6 +208,32 @@ General-purpose aggregation functions
Examples are the same as for :attr:`ArrayAgg.ordering`.
+ Usage example::
+
+ class Publication(models.Model):
+ title = models.CharField(max_length=30)
+
+ class Article(models.Model):
+ headline = models.CharField(max_length=100)
+ publications = models.ManyToManyField(Publication)
+
+ >>> article = Article.objects.create(headline="NASA uses Python")
+ >>> article.publications.create(title="The Python Journal")
+ <Publication: Publication object (1)>
+ >>> article.publications.create(title="Science News")
+ <Publication: Publication object (2)>
+ >>> from django.contrib.postgres.aggregates import StringAgg
+ >>> Article.objects.annotate(
+ ... publication_names=StringAgg(
+ ... "publications__title",
+ ... delimiter=", ",
+ ... ordering="publications__title",
+ ... )
+ ... ).values("headline", "publication_names")
+ <QuerySet [{
+ 'headline': 'NASA uses Python', 'publication_names': 'Science News, The Python Journal'
+ }]>
+
.. deprecated:: 4.0
If there are no rows and ``default`` is not provided, ``StringAgg``