我只需要从模型中删除规定的元顺序。你可以通过
.order_by()在子查询中添加一个空白来实现。在我的代码中,这意味着:
spaces = Space.objects.filter(carpark=OuterRef('pk')).order_by().values('carpark')count_spaces = spaces.annotate(c=Count('*')).values('c')Carpark.objects.annotate(space_count=Subquery(count_spaces))


