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 have been a ForeignKey
instead of a ManyToManyField
, when I display Action
as a TabularInline
in Sample
in the Django Admin, I would get a number of rows, each containing a nice form to edit or add another Action
. However; when I display the above as an inline using the following:
class ActionInline(admin.TabularInline):
model=Action.samples.through
I get a select box listing all available actions, and not a nifty form to create a new Action
.
My question is really: How do I display the ManyToMany relation as an inline with a form to input information as described?
In principle it should be possible since, from the Sample
's point of view, the situation is identical in both cases; Each Sample
has a list of Action
s regardless if the relation is a ForeignKey
or a ManyToManyRelation
. Also; Through the Sample
admin page, I never want to choose from existing Action
s, only create new or edit old ones.