Django queryset annotate field to be a list/queryset

后端 未结 2 1899
逝去的感伤
逝去的感伤 2020-12-29 12:06

I\'m trying to use django annotation to create queryset field which is a list of values of some related model attribute.

queryset = ...
qs = queryset.annotat         


        
2条回答
  •  遥遥无期
    2020-12-29 12:46

    If you are using postgresql and django >= 1.9, you could use postgres specific aggregating functions e.g. ArrayAgg:

    Returns a list of values, including nulls, concatenated into an array.

    In case, you need to concatenate these values using a delimiter, you could also use StringAgg.

提交回复
热议问题