我有以下两个使用多表继承的模型。 PlayerAchievment扩展了整体成就:
class OverallAchievment(models.Model):
achievement = models.ForeignKey(Achievement)
match = models.ForeignKey(Match, limit_choices_to={'week_number': 2})
created_at = models.DateTimeField(auto_now_add = True)
updated_at = models.DateTimeField(auto_now = True)
class PlayerAchievement(OverallAchievment):
player = models.ForeignKey(Player)
def __unicode__(self):
return self.player.first_name + ' ' + self.player.last_name
def match_detail(self):
??? how to get match info here?
我想在PlayerAchievement子函数中提取有关父级匹配属性的一些信息。
我该怎么做?
答案 0 :(得分:2)
由于PlayerAchievement
从OverallAchievment
延伸,您可以使用其属性:
def match_detail(self):
self.match.<attr_here>
...