diff options
author | Mads Jensen <mje@inducks.org> | 2016-09-26 13:16:03 +0200 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2016-10-07 07:52:03 -0400 |
commit | 0a26f3c3388137c336fb1417ba870fde12c0fbcc (patch) | |
tree | 6267b1295ee7b8d5a4f9e24f93516e81b393216d /django/contrib/postgres/aggregates/general.py | |
parent | 52188a5ca6bafea0a66f17baacb315d61c7b99cd (diff) | |
download | django-0a26f3c3388137c336fb1417ba870fde12c0fbcc.tar.gz |
Fixed #26327 -- Added JsonAgg to contrib.postgres.
Thanks Tim Graham for review.
Diffstat (limited to 'django/contrib/postgres/aggregates/general.py')
-rw-r--r-- | django/contrib/postgres/aggregates/general.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/django/contrib/postgres/aggregates/general.py b/django/contrib/postgres/aggregates/general.py index 6ff6727bd4..5d420505eb 100644 --- a/django/contrib/postgres/aggregates/general.py +++ b/django/contrib/postgres/aggregates/general.py @@ -1,7 +1,8 @@ +from django.contrib.postgres.fields import JSONField from django.db.models.aggregates import Aggregate __all__ = [ - 'ArrayAgg', 'BitAnd', 'BitOr', 'BoolAnd', 'BoolOr', 'StringAgg', + 'ArrayAgg', 'BitAnd', 'BitOr', 'BoolAnd', 'BoolOr', 'JsonAgg', 'StringAgg', ] @@ -30,6 +31,16 @@ class BoolOr(Aggregate): function = 'BOOL_OR' +class JsonAgg(Aggregate): + function = 'JSONB_AGG' + _output_field = JSONField() + + def convert_value(self, value, expression, connection, context): + if not value: + return [] + return value + + class StringAgg(Aggregate): function = 'STRING_AGG' template = "%(function)s(%(distinct)s%(expressions)s, '%(delimiter)s')" |