Opened 4 years ago

Closed 4 years ago

#22135 closed New feature (fixed)

Implement ModelAdmin.get_initial_data

Reported by: Adam Avramov Owned by: Greg Chapple
Component: contrib.admin Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


At the present moment, the admin's add view is hard-coded to get initial values from request.GET (see, which strikes me as quite inflexible. Would anyone be interested in seeing a get_initial_data(self, request) method added to ModelAdmin, which could then be overridden to specify arbitrary initial data for new objects?

Change History (6)

comment:1 Changed 4 years ago by Simon Charette

Triage Stage: UnreviewedAccepted
Version: 1.4master

Makes sense to me.

comment:2 Changed 4 years ago by Greg Chapple

Owner: changed from nobody to Greg Chapple
Status: newassigned

comment:3 Changed 4 years ago by Greg Chapple

Has patch: set

Created pull request for this ticket:

comment:4 Changed 4 years ago by Tim Graham

Patch needs improvement: set

Comments for improvement on the PR.

comment:5 Changed 4 years ago by Greg Chapple

Patch needs improvement: unset

I have just updated the pull request following comments.

comment:6 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 6acaa5238668593d6d854b28dbfa65e95796585c:

Fixed #22135 -- Added ModelAdmin.get_changeform_initial_data().

Allows custom behavior for setting initial form data in ModelAdmin.
By default, initial data is set via GET params. The new method allows
this behavior to be overridden.

Thanks egasimus for the suggestion.

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