Version 2 (modified by Joshua Tacoma, 18 years ago) ( diff )

--

The straight-forward way to do this with a relational database is to create an intermediary table (as Django does automatically with ManyToManyField) and then add fields to that table. Setting up this structure in Django is also straight-forward, but it took some work for me to find the right Field arguments to make it all work as I'd like on the admin side. Here's how I did it:

from django.db import models

class Individual (models.Model):
    #...
    class Admin: pass

class Event (models.Model):
    #...
    class Admin: pass

class Participation (models.Model):
    # leave defaults: null=False , core=False
    event = models.ForeignKey(Event, related_name='participants', edit_inline=True, blank=True, default=None)
    individual = models.ForeignKey(Individual, related_name='events', edit_inline=True, blank=True, default=None)
    # set core=True and blank=True: now admin will show it blank by default (so it won't exist unless you specify something)
    role = models.PositiveSmallIntegerField(core=True, blank=True, default=None)
    class Admin: pass
Note: See TracWiki for help on using the wiki.
Back to Top