Opened 13 years ago

Closed 9 years ago

#17577 closed New feature (duplicate)

Form instantiation hook for admin

Reported by: Simon Litchfield Owned by: Simon Litchfield
Component: contrib.admin Version: 1.3
Severity: Normal Keywords: admin forms modelforms request init add_view change_view validation
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: yes
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently there is no hook to alter how forms are instantiated in admin, without hacking add_view/change_view.

This simple change could allow some nice stuff like access to the request object for form validation, customising fields, etc.

http://stackoverflow.com/a/2684552/489638

http://stackoverflow.com/a/1388881/489638

Proposed syntax --

class MyAdmin(admin.ModelAdmin):
    ...
    def get_form_instance(self, request, obj=None):
        ... (default method calls get_form() here)


Change History (2)

comment:1 by Julien Phalip, 13 years ago

Needs documentation: set
Needs tests: set
Triage Stage: UnreviewedAccepted

Accepting in principle as it'd be nice to allow the customization of how forms get instantiated. However, the API needs more work, in particular to accommodate for the fact that the form may get instantiated in various ways (e.g. ModelForm(request.POST, request.FILES) or ModelForm(initial=initial) in add_view()). It would be useful also to see how the same thing could be done for inline forms.

comment:2 by Tim Graham, 9 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #10305

Note: See TracTickets for help on using tickets.
Back to Top