2011-09-08 132 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

回答