我有模型:
class Player(models.Model) :
...
teams = models.ManyToManyField("Team", through="PlayerTeam")
class Team(models.Model) :
...
players = models.ManyToManyField("Player", through="PlayerTeam")
class PlayerTeam(models.Model) :
player = models.ForeignKey(Player)
team = models.ForeignKey(Team)
date_begin = models.DateField()
date_end = models.DateField(blank=True, null=True)
我想获得所有在选定球队中比赛的球员(date_end 为空)。我试过这个:
team = get_object_or_404(Team, pk=id)
players = team.players.filter(date_end__isnull=True)
但它不起作用,因为字段 'date_end' 不在 Player 模型中