(I'm copying my question from Stack Overflow here 
<http://stackoverflow.com/questions/27518967/how-to-set-up-a-junction-table-in-django>
 because 
it didn't get any answers.  Please let me know if it's confusing.)

I'm trying to figure out the best way to model this data structure. I want 
to have a table of "Players" and and table of "Games" such that each game 
includes two or more players. E.g.

Players

PlayerID | PlayerName1        | John2        | Sue3        | Bob

Games

GameID | GameDate1      | 1/1/20142      | 2/1/2014

GamePlayers (junction table)

GamePlayerID | GameID | PlayerID 1            | 1      | 12            | 1      
| 23            | 1      | 34            | 2      | 25            | 2      | 
NULL

Notice the NULL value. This basically says "Game 2" consists of player 2 *and 
one undetermined* player. This functionality is what I need to replicate in 
Django. This is what I 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 can't seem to replicate the functionality I described 
above. How do I accomplish this?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/15216524-522f-41ec-a78b-bddcdcf6ad9b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to