簡體   English   中英

Django模型字段限制從其他模型字段中選擇

[英]django model field limit choice from other model fields

好吧,我正在做足球應用程序,我有一個固定裝置或游戲模型,它要做的是得到兩個團隊,而且它為比賽的進行增加了時間和東西,但是我還有FixtureRedCard和FixtureGoals,現在正在發生的是FixtureGoals和FixtureRedCard擁有3個字段,分別是燈具的外鍵和團隊的進球,然后球隊又進球來顯示哪個球員做到了……

基本治具類

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")

治具目標

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)

燈具紅卡

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)

我要做的是將選擇限制在Fixture上選擇的team_a和team_b中,對於fixtureredcard和Fixturegoal類中的現場團隊,我該如何實現?

謝謝

請查看此Django代碼段中的示例。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM