2011-09-08 140 views
1

嗯我在做一个足球应用程序,我有一个夹具或游戏模型,这样做是得到两个团队,以及它增加了一个时间和东西的游戏发生,但我也有FixtureRedCard和FixtureGoals,现在发生的事情是FixtureGoals和FixtureRedCard有3个字段,外键和外键给一个球队打进了另一个球门,显示哪个球员做到了这一点...django模型字段限制选择从其他模型领域

基本夹具类

class Fixture(TitleAndSlugModel): 
    """ 
    A division match fixture 
    """ 
    division = models.ForeignKey(Division) 
    fixture_date_time = models.DateTimeField() 
    team_a = models.ForeignKey("team.Team", related_name="team_a") 
    team_b = models.ForeignKey("team.Team", related_name="team_b") 

FixtureGoal

class FixtureGoal(BaseModel): 
    """ 
    A goal recorded against a match fixture 
    """ 
    fixture = models.ForeignKey(Fixture) 
    team = models.ForeignKey("team.Team") 
    player = ChainedForeignKey(
     "team.TeamPlayer", 
     chained_field="team", 
     chained_model_field="team", 
     show_all=False, 
     auto_choose=True, 
     blank=True, null=True) 

    class Meta: 
     ordering = ["fixture", "team",] 

    def __unicode__(self): 
     return u'%s (%s)' % (self.fixture, self.player) 

FixtureRedCard

class FixtureRedCard(BaseModel): 
    """ 
    A red card recorded against a match fixture 
    """ 
    fixture = models.ForeignKey(Fixture) 
    team = models.ForeignKey("team.Team") 
    player = ChainedForeignKey(
     "team.TeamPlayer", 
     chained_field="team", 
     chained_model_field="team", 
     show_all=False, 
     auto_choose=True, 
     blank=True, null=True) 

    class Meta: 
     ordering = ["fixture", "team",] 

    def __unicode__(self): 
     return u'%s (%s)' % (self.fixture, self.player) 

我想要做的是限制了选择,team_a和team_b在fixtureredcard和fixturegoal类选择上夹具,用于野队,我怎么能做到这一点?

谢谢

+0

您是否指的是在管理中限制ModelForm中的选择?要么? – Brandon

+0

噢,管理员! – maumercado

回答