聚合 Concat

from django.db.models import Aggregate, CharField
class Concat(Aggregate):
    """ORM用来分组显示其他字段 相当于group_concat"""
    function = 'GROUP_CONCAT'
    template = '%(function)s(%(distinct)s%(expressions)s)'

    def __init__(self, expression, distinct=False, **extra):
        super(Concat, self).__init__(
            expression,
            distinct='DISTINCT ' if distinct else '',
            output_field=CharField(),
            **extra)
ipall = obj.server.ip_set.all().values("attribute").annotate(xx=Concat("ip"))

  

 

posted on 2020-04-14 13:47  谢Rain  阅读(136)  评论(0编辑  收藏  举报