Skip to content

Commit 39f5bc7

Browse files
committed
Fixed django#16841 - Documented a couple ModelAdmin methods
* ModelAdmin.get_changelist_form and get_changelist_formset * InlineModelAdmin.get_formset Thanks Jordan Reiter for the report.
1 parent 965cc0b commit 39f5bc7

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

docs/ref/contrib/admin/index.txt

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,10 +1233,39 @@ templates used by the :class:`ModelAdmin` views:
12331233

12341234
.. method:: ModelAdmin.get_changelist(self, request, **kwargs)
12351235

1236-
Returns the Changelist class to be used for listing. By default,
1236+
Returns the ``Changelist`` class to be used for listing. By default,
12371237
``django.contrib.admin.views.main.ChangeList`` is used. By inheriting this
12381238
class you can change the behavior of the listing.
12391239

1240+
.. method:: ModelAdmin.get_changelist_form(self, request, **kwargs)
1241+
1242+
Returns a :class:`~django.forms.ModelForm` class for use in the ``Formset``
1243+
on the changelist page. To use a custom form, for example::
1244+
1245+
class MyForm(forms.ModelForm):
1246+
class Meta:
1247+
model = MyModel
1248+
1249+
class MyModelAdmin(admin.ModelAdmin):
1250+
def get_changelist_form(self, request, **kwargs):
1251+
return MyForm
1252+
1253+
.. method:: ModelAdmin.get_changelist_formset(self, request, **kwargs)
1254+
1255+
Returns a :ref:`ModelFormSet <model-formsets>` class for use on the
1256+
changelist page if :attr:`~ModelAdmin.list_editable` is used. To use a
1257+
custom formset, for example::
1258+
1259+
from django.forms.models import BaseModelFormSet
1260+
1261+
class MyAdminFormSet(BaseModelFormSet):
1262+
pass
1263+
1264+
class MyModelAdmin(admin.ModelAdmin):
1265+
def get_changelist_formset(self, request, **kwargs):
1266+
kwargs['formset'] = MyAdminFormSet
1267+
return super(MyModelAdmin, self).get_changelist_formset(request, **kwargs)
1268+
12401269
.. method:: ModelAdmin.has_add_permission(self, request)
12411270

12421271
Should return ``True`` if adding an object is permitted, ``False``
@@ -1552,6 +1581,10 @@ The ``InlineModelAdmin`` class adds:
15521581
Specifies whether or not inline objects can be deleted in the inline.
15531582
Defaults to ``True``.
15541583

1584+
.. method:: InlineModelAdmin.get_formset(self, request, obj=None, **kwargs)
1585+
1586+
Returns a ``BaseInlineFormSet`` class for use in admin add/change views.
1587+
See the example for :class:`ModelAdmin.get_formsets`.
15551588

15561589
Working with a model with two or more foreign keys to the same parent model
15571590
---------------------------------------------------------------------------

0 commit comments

Comments
 (0)