1
0
mirror of https://github.com/django/django.git synced 2025-10-25 14:46:09 +00:00

Fixed #26327 -- Added JsonAgg to contrib.postgres.

Thanks Tim Graham for review.
This commit is contained in:
Mads Jensen
2016-09-26 13:16:03 +02:00
committed by Tim Graham
parent 52188a5ca6
commit 0a26f3c338
4 changed files with 46 additions and 6 deletions

View File

@@ -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')"