简体   繁体   English

Django - 为锦标赛创建 model

[英]Django - creating model for a tournament

I have a problem with my model, i don't know how to create model called battle, because i want to choose two users from my database but i don't know how to create it我的 model 有问题,我不知道如何创建名为战斗的 model,因为我想从我的数据库中选择两个用户,但我不知道如何创建它

class battle(models.Model):
    user1 = models.ForeignKey(Debatants, on_delete=models.DO_NOTHING)
    user2 = models.ForeignKey(Debatants, on_delete=models.DO_NOTHING)
    judge = models.ForeignKey(Judges, on_delete=models.DO_NOTHING)
    data = models.DateField(auto_now_add=False, auto_now=False)

I'd appreciate any hint我会很感激任何提示

Try to add unique related name with forign key relationships,尝试添加具有外键关系的唯一相关名称,

for example例如

user1 = models.ForeignKey(Debatants, on_delete=models.DO_NOTHING, related_name="battles")

so the Debatants relate to this model as battles所以辩论者把这个 model 作为战斗

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM