How to customize the join table in Django
I am trying to find the best way to model this data structure. I want to have a Players table and a Games table so that every game has two or more players. For example.
Players
PlayerID | PlayerName
1 | John
2 | Sue
3 | Bob
Games
GameID | GameDate
1 | 1/1/2014
2 | 2/1/2014
GamePlayers (join table)
GamePlayerID | GameID | PlayerID
1 | 1 | 1
2 | 1 | 2
3 | 1 | 3
4 | 2 | 2
5 | 2 | NULL
Note the NULL value. Basically it says that "Game 2" consists of player 2 and one undefined player . This functionality is what I need for replication in Django. This is what I have tried.
Models.py
class Player(models.Model):
player_name = models.CharField(max_length=60)
class Game(models.Model):
players = models.ManyToManyField(Player, blank=True)
game_date = models.DateField(null=True, blank=True)
But with this setup, I cannot reproduce the functionality described above. How to do it?
+3
source to share
No one has answered this question yet
Check out similar questions: