Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.5.X] Fixed #16841 - Documented a couple ModelAdmin methods

* ModelAdmin.get_changelist_form and get_changelist_formset
* InlineModelAdmin.get_formset

Thanks Jordan Reiter for the report.

Backport of 39f5bc7 from master
  • Loading branch information...
commit 4a9b3826fdfa1d78f640d4fee922005ed8210498 1 parent 0131da0
Tim Graham authored November 03, 2012

Showing 1 changed file with 34 additions and 1 deletion. Show diff stats Hide diff stats

  1. 35  docs/ref/contrib/admin/index.txt
35  docs/ref/contrib/admin/index.txt
@@ -1233,10 +1233,39 @@ templates used by the :class:`ModelAdmin` views:
1233 1233
 
1234 1234
 .. method:: ModelAdmin.get_changelist(self, request, **kwargs)
1235 1235
 
1236  
-    Returns the Changelist class to be used for listing. By default,
  1236
+    Returns the ``Changelist`` class to be used for listing. By default,
1237 1237
     ``django.contrib.admin.views.main.ChangeList`` is used. By inheriting this
1238 1238
     class you can change the behavior of the listing.
1239 1239
 
  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
+
1240 1269
 .. method:: ModelAdmin.has_add_permission(self, request)
1241 1270
 
1242 1271
     Should return ``True`` if adding an object is permitted, ``False``
@@ -1552,6 +1581,10 @@ The ``InlineModelAdmin`` class adds:
1552 1581
     Specifies whether or not inline objects can be deleted in the inline.
1553 1582
     Defaults to ``True``.
1554 1583
 
  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`.
1555 1588
 
1556 1589
 Working with a model with two or more foreign keys to the same parent model
1557 1590
 ---------------------------------------------------------------------------

0 notes on commit 4a9b382

Please sign in to comment.
Something went wrong with that request. Please try again.