I think what I need to do is really the opposite of an inlineformset.
Say I have:
from django.db import models
class Type(models.Model):
description = models.CharField(max_length=50)
status = models.ForeignKey(Status)
def __unicode__(self):
return self.description
class ColorType(models.Model):
type = models.ForeignKey(Type)
color = models.ForeignKey('Color')
status = models.ForeignKey(Status)
def __unicode__(self):
return u'%s %s' % (self.type, self.color)
class Color(models.Model):
description = models.CharField(max_length=50)
status = models.ForeignKey(Status)
types = models.ManyToManyField(type, through=ColorType)
def __unicode__(self):
return self.description
class Chair(models.Model):
description = models.CharField(max_length=50)
status = models.ForeignKey(Status)
colorType = models.ForeignKey(ColorType)
Now I need a form to edit a chair in which I enter Color and Type separatedly (Like showing a modelformset of ColorType). If the combination doesn't exist the application has to create the necessary instance of ColorType (and assigning it a desfault status) and assign it to the chair.
I think the whole situation is common, I should be missing something...