Version 3 (modified by 18 years ago) ( diff ) | ,
---|
The [source:trunk/tests/testapp/models/m2m_intermediary.py Many-to-Many Intermediary] test case already shows how this is structured. What I add here is a set of parameters for the fields in the intermediary model that allow smooth inline editing in admin.
from django.db import models class Individual (models.Model): class Admin: pass class Event (models.Model): class Admin: pass class Participation (models.Model): 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) role = models.PositiveSmallIntegerField(core=True, blank=True, default=None) class Admin: pass
edit_inline=True
core=False
# So that when anIndividual
is being created along with a fewParticipations
created inline, theParticipation
records will be valid even though theIndividual
doesn't fully exist yet.blank=True, default=None
# So that untouched inline records will have blank core values and thus will not be created.
Note:
See TracWiki
for help on using the wiki.