On 2014-12-17 06:34, Ben Gorman wrote: > 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?
Sounds like you want to use the "through" property of a ManyToMany field¹, something like class Player(models.Model): # ... class Game(models.Model): # ... players = models.ManyToMany(Player, through="PlayerGame") class PlayerGame(models.Model): player = models.ForeignKey(Player) game = models.ForeignKey(Game, blank=True, null=True) # possible other attributes of a PlayerGame -tkc ¹ https://docs.djangoproject.com/en/1.7/ref/models/fields/#django.db.models.ManyToManyField.through . -- 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/20141217111901.70140441%40bigbox.christie.dr. For more options, visit https://groups.google.com/d/optout.