def build_aggregate(self, queryset, compiler):
agg = super(ManyToOneConstructor, self).build_aggregate(queryset, compiler)
# Any ordering needs to be plucked from the query set and added into the JSONAgg that we will be build
# because SQL
kwargs = {}
if queryset.ordered:
kwargs['order_by'] = next(zip(*queryset.query.get_compiler(connection=compiler.connection).get_order_by()))
queryset.query.clear_ordering(True)
# many_to_one is a bit of a misnomer, the field we have is the "one" side
return JSONAgg(agg, **kwargs)
评论列表
文章目录