我遇到类似以下情况:
class Team(models.Model):
pass
class Player(models.Model):
team = models.ForeignKey(Team)
class Point(models.Model):
player = models.ForeignKey(Player)
出于订购目的(使用django-tables2),我想用团队的总点数对QuerySet进行注释,类似于以下内容:
Team.objects.annotate(point_count=Count('player_set__point_set')) \
.order_by('point_count')
但是,这不起作用。有没有办法达到相同的目的?