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:
@@ -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')"
|
||||
|
||||
Reference in New Issue
Block a user