user628154
user628154

Reputation: 101

howto add custom form into django administrator page inlines

Can I get a form into Django Administrator page, that I have defined in forms.py? Can I also get this form into Model inlines of Django Administrator page ?

To be clear, this is what I call inline:

class AnswerInline(admin.StackedInline):
  ...

Upvotes: 10

Views: 14322

Answers (1)

Jordan Reiter
Jordan Reiter

Reputation: 21002

Yeah, it's a bit complicated but the docs are actually clear here:

InlineModelAdmin.form
The value for form defaults to ModelForm. This is what is passed through to inlineformset_factory when creating the formset for this inline.

So create your form class and then refer to it in the inline, like so:

class MyForm(forms.ModelForm):
    …

class AnswerInLine(admin.StackedInline):
    form = MyForm

Upvotes: 11

Related Questions