#10305: Add a form instantiation hook for contrib.admin add/change views
-------------------------------------+-------------------------------------
Reporter: tangc | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: add_view, | Triage Stage: Accepted
change_view, ModelForm |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Romaric Pascal):
I've ran into the exact same need and thought it'd be great if ModelAdmin
had that `instanciate_form` hook.
How does the following sound: The calls to `ModelForm(...)` inside
[https://github.com/django/django/blob/0668164b4ac93a5be79f5b87fae83c657124d9ab/django/contrib/admin/options.py#L1536
_changeform_view] could be replaced by `self.get_form_instance(ModelForm,
request, obj,...)` which would pass any arguments to the ModelForm, but
allow developers to intercept the call and maybe set initial values of
their own based on the request or the current object.
Actually the `get_form_instance` default implementation could also be
responsible for calling the `get_form` so that the signature doesn't
require the form class to be passed (but that might be too many
responsibilities for it and make things confusing).
Would be happy to contribute the change if that was fitting :D
--
Ticket URL: <https://code.djangoproject.com/ticket/10305#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/062.26c0da8d3a812e9a56444694a57d53ee%40djangoproject.com.