#34199: Add documentation for contrib.postgres.aggregates.StringAgg
-------------------------------------+-------------------------------------
               Reporter:  Mark       |          Owner:  Mark Gensler
  Gensler                            |
                   Type:             |         Status:  assigned
  Uncategorized                      |
              Component:             |        Version:  dev
  Documentation                      |
               Severity:  Normal     |       Keywords:  postgres StringAgg
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 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.
 {{{#!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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070184d7b84791-29ce033a-5e57-493e-9ade-02f1ce51befe-000000%40eu-central-1.amazonses.com.

Reply via email to