Code

Opened 2 years ago

Last modified 2 years ago

#17577 new New feature

Form instantiation hook for admin

Reported by: simon29 Owned by: simon29
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)


Attachments (0)

Change History (1)

comment:1 Changed 2 years ago by julien

  • Needs documentation set
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new
The owner will be changed from simon29 to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.