I'm fairly new to Django and having read the documentation on its relational models and inline admin forms (docs on InlineModelAdmin) I'm struggling to figure out if the following is possible out of the box, or if I should roll my own forms.
Let's say I have two objects: Films and Directors, this is a many-to-many relationship as defined in in the model declarations as follows:
class Film(Model):
director = ManyToManyField('Director')
Now in the detail form for a Film object I would like to add inline Director objects (they just have a name field as sole property). Not just selecting existing instances, but being able to create new ones, inline in the form of the Film object.
class DirectorInline(admin.TabularInline):
model = Director
extra = 3
class FilmAdmin(admin.ModelAdmin):
inlines = (
DirectorInline,
)
This throws an error, because it expects a foreign key on the Director object. Is what I'm trying to achieve possible without creating a custom form, validator etc. ? Any tips in the right direction would be greatly appreciated, thanks in advance.