10

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):
  ...
user628154
  • 101
  • 1
  • 1
  • 4
  • You want to define your own formset, look at http://stackoverflow.com/questions/877723/inline-form-validation-in-django#877920 – krs Nov 15 '11 at 00:33
  • Is there a simple resource I can refer to, in order to understand where and How to use forms in general. The Django documentation is a little cryptic to me right now. – Divij Sehgal Jul 19 '17 at 11:10

1 Answers1

11

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
Igor Jerosimić
  • 13,621
  • 6
  • 44
  • 53
Jordan Reiter
  • 20,467
  • 11
  • 95
  • 161