I have a model similar to the following (simplified):
models.py class Sample(models.Model): name=models.CharField(max_length=200) class Action(models.Model): samples=models.ManyToManyField(Sample) title=models.CharField(max_length=200) description=models.TextField()
Now, if Action.samples would be ForeignKey instead of ManyToManyField , when I show Action as TabularInline in Sample in Django Admin, I would get several lines, each of which contains a nice form for editing or adding another Action . However; when I post the above as inline using the following:
class ActionInline(admin.TabularInline): model=Action.samples.through
I get a selection box that lists all the available actions, and not a great form for creating a new Action .
My question really is: how to display the ManyToMany relation as inline with the form for entering information, as described?
In principle, this should be possible, since from the point of view of Sample situation is the same in both cases; Each Sample has an Action list, regardless of whether the relationship is ForeignKey or ManyToManyRelation . Also; Through the Sample admin page, I never want to select from existing Action s, create only new ones or edit old ones.
source share