mirror of
https://github.com/django/django.git
synced 2025-09-15 06:55:32 +00:00
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.
This commit is contained in:
parent
6b63742ce5
commit
6acaa52386
5 changed files with 53 additions and 10 deletions
|
@ -1709,6 +1709,21 @@ templates used by the :class:`ModelAdmin` views:
|
|||
``obj_display`` is a string with the name of the deleted
|
||||
object.
|
||||
|
||||
.. method:: ModelAdmin.get_changeform_initial_data(request)
|
||||
|
||||
.. versionadded:: 1.7
|
||||
|
||||
A hook for the initial data on admin change forms. By default, fields are
|
||||
given initial values from ``GET`` parameters. For instance,
|
||||
``?name=initial_value`` will set the ``name`` field's initial value to be
|
||||
``initial_value``.
|
||||
|
||||
This method should return a dictionary in the form
|
||||
``{'fieldname': 'fieldval'}``::
|
||||
|
||||
def get_changeform_initial_data(self, request):
|
||||
return {'name': 'custom_initial_value'}
|
||||
|
||||
Other methods
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
|
|
|
@ -308,6 +308,10 @@ Minor features
|
|||
<django.contrib.admin.ModelAdmin.list_display>` value by prefixing the
|
||||
``admin_order_field`` value with a hyphen.
|
||||
|
||||
* The :meth:`ModelAdmin.get_changeform_initial_data()
|
||||
<django.contrib.admin.ModelAdmin.get_changeform_initial_data>` method may be
|
||||
overridden to define custom behavior for setting initial change form data.
|
||||
|
||||
:mod:`django.contrib.auth`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue