class Team(models.Model): college = models.CharField(max_length=20) image = models.FileField(upload_to='documents/',null=True) def __str__(self): return self.college class Athletics(Match): time = ? player = models.ManyToManyField(Player, related_name='player') game_level = models.CharField(max_length=256, null=True, choices=LEVEL_CHOICES) # like semi-final, final etc game_specific = models.CharField(max_length=256,null=True, choices=EVENT_CHOICES) #like Men's Shot Put or Men's Triple Jump etc def __str__(self): return str(self.game_level)我正在为体育比赛制作田径运动模型。我有一个现有的球员模型,其中列出了球员名称和他们的球队。现在您可以看到,我已经将玩家字段添加为ManyToManyField以供选择4-5个玩家匹配。现在我需要每个球员的完成时间来判断谁有资格参加下一轮比赛。只能在此模型中执行此操作吗?还是我必须添加其他模型?帮我!
1 回答
PIPIONE
TA贡献1829条经验 获得超9个赞
您需要一个介于Player和Athletics之间的中间模型来记录特定于这两个模型的多对多关系的信息。请阅读关于多对多关系的其他字段。
class PlayeAthletics(models.Model):
player = models.ForeignKey(Player, on_delete=models.CASCADE)
athletics = models.ForeignKey(Athletics, on_delete=models.CASCADE)
time = models.IntegerField()
class Athletics(Match):
player = models.ManyToManyField(Player, through='PlayerAthletics')
添加回答
举报
0/150
提交
取消