Custom forms in Django admin?

83 views
Skip to first unread message

Kevin Olbrich

unread,
Apr 8, 2019, 5:26:12 AM4/8/19
to Django users
Hi!

Is it possible to add a form to the Django admin?
Models are no problem but I have a slightly more complex requirement (still less than a full view with templates, etc.).

Kind regards
Kevin

Erik van widenfelt

unread,
Apr 8, 2019, 5:44:49 PM4/8/19
to Django users
Hi Kevin


Staying within the admin, you can create your own form class (forms.ModelForm) and specify it in the ModelAdmin declaration. See also django modelforms.

As you can see from the docs there is a lot you can do. I recommend leaving Admin to do most of the work. I do, however, use my own ModelForm instead of the default ModelAdmin form to override the `clean()` method (modelforms (validation)). With a custom form, I can do a more comprehensive validation of the user's input. 

hope this helps

-erik
Reply all
Reply to author
Forward
0 new messages