作者:国芝翰娥264 | 来源:互联网 | 2023-09-23 12:33
Iamsettingupamodelwheretwoplayersareinvolvedinacompetition.Imleaningtowardsthismo
I am setting up a model where two players are involved in a competition. I'm leaning towards this model:
我正在建立一个模型,在这个模型中有两个参与者参与竞争。我倾向于这种模式:
def match(models.Model):
player = ForeignKey(Player)
oppOnent= ForeignKey(Player)
score = PositiveSmallIntegerField()
games_won = PositiveSmallIntegerField()
games_lost = PositiveSmallIntegerField()
won_match = BooleanField()
There are statistics involved, however, and it would require another pull to find the matching record for the opponent if I want to describe the match in full.
不过,这里涉及到一些统计数据,如果我想完整地描述这场比赛,就需要再次拉拽才能找到对手的匹配记录。
Alternatively I could set up the model to include full stats:
或者,我可以建立模型,包括完整的统计数据:
def match(models.Model):
home_player = ForeignKey(Player)
away_player = ForeignKey(Player)
home_player_score = PositiveSmallIntegerField()
away_player_score = PositiveSmallIntegerField()
...
But that seems equally bad, as I would have to do two logic sets for one player (to find his scores when he's home_player and his scores when he's away_player).
但这似乎同样糟糕,因为我必须为一个玩家设置两个逻辑集(在他在家的时候查找他的分数,在他不在的时候查找他的分数)。
The final option is to do two inserts per match, both with full stats, and keep redundant data in the table.
最后一个选项是每次匹配做两个插入,都有完整的统计数据,并在表中保留冗余数据。
There seems like a better way, and therefore I poll SO.
似乎有更好的方法,所以我投票了。
3 个解决方案