Create Django Team / Player where order does matter

Viewed 18

I'm creating a database of all races that are won by players of our club. Goal is to have an overview of all the races that are won, but also a per_player count of the wins.

A person in the database can be either be an player or a coach, or both, but not during the same race. A race can be with 1, 2,4 or 8 persons and the order of the players does matter, so I therefore think that a ManyToMany field is not working (only showed up to 4). I now solved it with 8 OneToOneField's. There must always be 1 player, so the first cannot be blank. teams tend to change from race to race, and can be different in a number of players, so, therefore, didn't create a Crew class.

class Person(models.Model):
    letters = models.CharField(max_length=10, blank = False)
    name    = models.CharField(max_length = 100, blank = True)
    tussen  = models.CharField(max_length = 50,     blank = True)
    lastname = models.CharField(max_length = 100,   blank = False)
    starting_year = models.IntegerField(blank = True)

class RaceWin(models.Model):
    name = models.CharField(max_length =100, blank = False)
    year        = models.IntegerField(blank = False)
    month       = models.IntegerField(blank = True, null = True)        
    athlete_1 = models.OneToOneField(Person, on_delete = models.CASCADE, related_name='athlete1', blank = False)
    athlete_2 = models.OneToOneField(Person, on_delete = models.SET_NULL, related_name='athlete2', blank = True, null = True)
    athlete_3 = models.OneToOneField(Person, on_delete = models.SET_NULL, related_name='athlete3', blank = True, null = True)   
    athlete_4 = models.OneToOneField(Person, on_delete = models.SET_NULL, related_name='athlete4', blank = True, null = True)   
    coach   = models.OneToOneField(Person, on_delete = models.SET_NULL, related_name='coach', blank = True, null = True)

I now need to iterate over 8 players to check the number of wins, but I'm not entirely sure how I can do this. Is there a better way to differentiate between the 8 possible player, while keeping their order?

Secondly, In this example I assumed that all athletes come from my club, but mixed clubteams are also possible. For those athletes I want to store the club they are from, but not their starting_year. So I thought of this solution to store the differences.

class Person(models.Model):
    letters = models.CharField(max_length=10, blank = True)
    name    = models.CharField(max_length = 100, blank = True)
    tussen  = models.CharField(max_length = 50,     blank = True)
    surname = models.CharField(max_length = 100,    blank = False)

class Member(Person):
    arrival_year = models.IntegerField(blank = True)

class NonMember(Person):
    club = models.CharField(max_length = 100)
0 Answers
Related