#31691: django.contrib.postgres.aggregates.JSONBAgg does not support ordering
-------------------------------------+-------------------------------------
Reporter: john- | Owner: nobody
parton |
Type: New | Status: new
feature |
Component: Database | Version: 3.0
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Here's a contrived example:
{{{#!python
class Author(models.Model):
name = models.CharField(max_length=50)
alias = models.CharField(max_length=50, null=True, blank=True)
age = models.PositiveSmallIntegerField(default=30)
class Article(models.Model):
authors = models.ManyToManyField(Author, related_name='articles')
title = models.CharField(max_length=50)
Article.objects.annotate(
authors_json=JSONBAgg(
Func(
Value('name'), 'name',
Value('alias'), 'alias',
ordering='age'
)
)
)
}}}
The ordering kwarg is ignored, but Postgres would have no problem
understanding the aggregate with an ORDER BY clause
In my code I did the following
{{{#!python
class OrderableJSONBAgg(OrderableAggMixin, JSONBAgg)
pass
from myapp.aggregates import OrderableJSONBAgg as JSONBAgg
}}}
I believe adding that mixin is all that would be required to add this
functionality.
--
Ticket URL: <https://code.djangoproject.com/ticket/31691>
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/054.916b6d8dfead05e53a1a019a519522d1%40djangoproject.com.