#34199 closed Cleanup/optimization (fixed)
Add an example for contrib.postgres.aggregates.StringAgg to docs.
Reported by: | Mark Gensler | Owned by: | Mark Gensler |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | postgres StringAgg |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The documentation is missing an example for StringAgg. Also I thought it would be useful to include an example for ManyToMany fields, in contrast to the OneToMany example for JSONBAgg.
I.e.
class Publication(models.Model): title = models.CharField(max_length=30) class Article(model.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') >>> article.publications.create(title='Science News') >>> 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' ]}]>
Change History (7)
comment:1 by , 2 years ago
Has patch: | set |
---|
comment:2 by , 2 years ago
comment:3 by , 2 years ago
Hi David, you're welcome! Thanks for letting me know, I will just make a PR for something like this in future.
Mark
comment:4 by , 2 years ago
Summary: | Add documentation for contrib.postgres.aggregates.StringAgg → Add an example for contrib.postgres.aggregates.StringAgg to docs. |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/optimization |
Note:
See TracTickets
for help on using tickets.
Hi Mark,
Thanks for the input!
Just FYI you don't need a ticket for trivial documentation updates. I think an example like this may fall under that category 👍