Reputation: 4109
I have the following models involved: Team, Stage, Group and LeaderBoard.
A Team play in every Stage of a tournament in a Group with other teams and I would a LeaderBoard model to store the rank of the group. I use a leaderboard outside the Group because it could be round-robin (I need it) or knockout (I don't need it). I can't just set a score field in Team because in every Stage it will reset and I need to reuse old ones.
So I think (maybe there is a better solution) I need in the LeaderBoard a sort of dictionary where all the teams I choose in the ManyToManyForm are stored with their scores.
Here my cleaned models.py file (sorry for some Italian in it):
class Stage(models.Model): # Fase
tournament = models.ForeignKey(Tournament, on_delete=models.CASCADE, related_name='stages')
class Group(models.Model): # Girone
FORMAT_TYPES = (('Round-Robin', "All'italiana"), ('Elimination', 'Ad eliminazione'))
stage = models.ForeignKey(Stage, on_delete=models.CASCADE, related_name='groups')
format = models.CharField(max_length=4, choices=FORMAT_TYPES, blank=True)
teams = models.ManyToManyField(Team)
class LeaderBoard(models.Model):
group = models.OneToOneField(Group, on_delete=models.CASCADE, blank=True, null=True)
Upvotes: 0
Views: 32
Reputation: 163
I think I understand what you are trying to do. If teams are going head to head you could make two new models Match and Score. Match is related back to two teams and then two Scores are related back to teams and matches.
Using this system you could report scores and matches that are inside stages and groups etc.
If I am way off on my interpretation of what you are trying to do, let me know
Upvotes: 1
Reputation: 4109
I think the best way for this is setting up a new whole class called Score with two ForeignKey, one for the Team, one for the LeaderBoard
Upvotes: 0