mirror of
https://github.com/himool/HimoolERP.git
synced 2026-01-13 21:04:11 +08:00
16 lines
610 B
Python
16 lines
610 B
Python
from django.db.models import Aggregate, CharField
|
|
|
|
|
|
class GroupConcat(Aggregate):
|
|
function = 'GROUP_CONCAT'
|
|
template = '%(function)s(%(distinct)s%(expressions)s%(ordering)s%(separator)s)'
|
|
|
|
def __init__(self, expression, distinct=False, ordering=None, separator=',', **extra):
|
|
super(GroupConcat, self).__init__(
|
|
expression,
|
|
distinct='DISTINCT ' if distinct else '',
|
|
ordering=' ORDER BY %s' % ordering if ordering is not None else '',
|
|
separator=' SEPARATOR "%s"' % separator,
|
|
output_field=CharField(),
|
|
**extra
|
|
)
|