summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authormanav014 <dpsman13016@gmail.com>2020-11-27 02:21:35 +0530
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-02-15 11:37:35 +0100
commit3119a6decab7788eca662b10e8c18351d20df212 (patch)
tree26124a74d44cc9109cbcf43523d92a60ac2e91d0 /docs
parent600ff26a85752071da36e3a94c66dd8a77ee314a (diff)
Fixed #26607 -- Allowed customizing formset kwargs with ModelAdmin.get_formset_kwargs().
Thanks Nick Pope for reviews.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/contrib/admin/index.txt16
-rw-r--r--docs/releases/4.0.txt3
2 files changed, 19 insertions, 0 deletions
diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt
index 1fd5d0f60a..5b3493c858 100644
--- a/docs/ref/contrib/admin/index.txt
+++ b/docs/ref/contrib/admin/index.txt
@@ -2088,6 +2088,22 @@ templates used by the :class:`ModelAdmin` views:
``obj_id`` is the serialized identifier used to retrieve the object to be
deleted.
+.. method:: ModelAdmin.get_formset_kwargs(request, obj, inline, prefix)
+
+ .. versionadded:: 4.0
+
+ A hook for customizing the keyword arguments passed to the constructor of a
+ formset. For example, to pass ``request`` to formset forms::
+
+ class MyModelAdmin(admin.ModelAdmin):
+ def get_formset_kwargs(self, request, obj, inline, prefix):
+ return {
+ **super().get_formset_kwargs(request, obj, inline, prefix),
+ 'form_kwargs': {'request': request},
+ }
+
+ You can also used it to set ``initial`` for formset forms.
+
.. method:: ModelAdmin.get_changeform_initial_data(request)
A hook for the initial data on admin change forms. By default, fields are
diff --git a/docs/releases/4.0.txt b/docs/releases/4.0.txt
index 1339b88f24..f1a25d0d92 100644
--- a/docs/releases/4.0.txt
+++ b/docs/releases/4.0.txt
@@ -37,6 +37,9 @@ Minor features
* The ``admin/base.html`` template now has a new block ``header`` which
contains the admin site header.
+* The new :meth:`.ModelAdmin.get_formset_kwargs` method allows customizing the
+ keyword arguments passed to the constructor of a formset.
+
:mod:`django.contrib.admindocs`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~