我的模型是这样的:
class PlayerProfile(models.Model):
user = models.OneToOneField(User)
team = models.ForeignKey(Team)
is_captain = models.BooleanField(default=False)
def __unicode__(self):
return self.user.get_username()
class Game(models.Model):
team = models.ForeignKey(Team)
game_time = models.DateTimeField()
location = models.CharField(max_length=100)
def __unicode__(self):
return self.team.name + ' ' + unicode(self.game_time)
class GameStatus(models.Model):
game = models.ForeignKey(Game, default=None, null=True)
team = models.ForeignKey(Team, default=None, null=True)
player = models.ForeignKey(PlayerProfile, default=None, null=True)
game_status = models.CharField(max_length=1)
是否可以在 PlayerProfile 中编写一个可以访问 GameStatus 模型的方法,以便我可以获得 game_status 属性(如果存在)?