Opened 10 years ago

Closed 10 years ago

#22135 closed New feature (fixed)

Implement ModelAdmin.get_initial_data

Reported by: Adam Avramov Owned by: Greg Chapple
Component: contrib.admin Version: dev
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

Description

At the present moment, the admin's add view is hard-coded to get initial values from request.GET (see https://github.com/django/django/blob/master/django/contrib/admin/options.py#L1363), 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 by Simon Charette, 10 years ago

Triage Stage: UnreviewedAccepted
Version: 1.4master

Makes sense to me.

comment:2 by Greg Chapple, 10 years ago

Owner: changed from nobody to Greg Chapple
Status: newassigned

comment:3 by Greg Chapple, 10 years ago

Has patch: set

Created pull request for this ticket: https://github.com/django/django/pull/2373

comment:4 by Tim Graham, 10 years ago

Patch needs improvement: set

Comments for improvement on the PR.

comment:5 by Greg Chapple, 10 years ago

Patch needs improvement: unset

I have just updated the pull request following comments.

comment:6 by Tim Graham <timograham@…>, 10 years ago

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