繁体   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