Opened 3 years ago

Closed 2 years ago

#22135 closed New feature (fixed)

Implement ModelAdmin.get_initial_data

Reported by: egasimus Owned by: gchp
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 3 years ago by charettes

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Version changed from 1.4 to master

Makes sense to me.

comment:2 Changed 3 years ago by gchp

  • Owner changed from nobody to gchp
  • Status changed from new to assigned

comment:3 Changed 3 years ago by gchp

  • Has patch set

Created pull request for this ticket:

comment:4 Changed 3 years ago by timo

  • Patch needs improvement set

Comments for improvement on the PR.

comment:5 Changed 3 years ago by gchp

  • Patch needs improvement unset

I have just updated the pull request following comments.

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

  • Resolution set to fixed
  • Status changed from assigned to closed

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