I.e.
{{{#!python
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'
]}]>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34199>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/34199#comment:1>
Comment (by David Sanders):
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 👍
--
Ticket URL: <https://code.djangoproject.com/ticket/34199#comment:2>
Comment (by Mark Gensler):
Hi David, you're welcome! Thanks for letting me know, I will just make a
PR for something like this in future.
Mark
--
Ticket URL: <https://code.djangoproject.com/ticket/34199#comment:3>