简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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