Skip to content

Commit

Permalink
Fixed #16841 - Documented a couple ModelAdmin methods
Browse files Browse the repository at this point in the history
* ModelAdmin.get_changelist_form and get_changelist_formset
* InlineModelAdmin.get_formset

Thanks Jordan Reiter for the report.
  • Loading branch information
timgraham committed Nov 3, 2012
1 parent 965cc0b commit 39f5bc7
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion docs/ref/contrib/admin/index.txt
Expand Up @@ -1233,10 +1233,39 @@ templates used by the :class:`ModelAdmin` views:

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

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

.. method:: ModelAdmin.get_changelist_form(self, request, **kwargs)

Returns a :class:`~django.forms.ModelForm` class for use in the ``Formset``
on the changelist page. To use a custom form, for example::

class MyForm(forms.ModelForm):
class Meta:
model = MyModel

class MyModelAdmin(admin.ModelAdmin):
def get_changelist_form(self, request, **kwargs):
return MyForm

.. method:: ModelAdmin.get_changelist_formset(self, request, **kwargs)

Returns a :ref:`ModelFormSet <model-formsets>` class for use on the
changelist page if :attr:`~ModelAdmin.list_editable` is used. To use a
custom formset, for example::

from django.forms.models import BaseModelFormSet

class MyAdminFormSet(BaseModelFormSet):
pass

class MyModelAdmin(admin.ModelAdmin):
def get_changelist_formset(self, request, **kwargs):
kwargs['formset'] = MyAdminFormSet
return super(MyModelAdmin, self).get_changelist_formset(request, **kwargs)

.. method:: ModelAdmin.has_add_permission(self, request)

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

.. method:: InlineModelAdmin.get_formset(self, request, obj=None, **kwargs)

Returns a ``BaseInlineFormSet`` class for use in admin add/change views.
See the example for :class:`ModelAdmin.get_formsets`.

Working with a model with two or more foreign keys to the same parent model
---------------------------------------------------------------------------
Expand Down

2 comments on commit 39f5bc7

@Shellbye
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed the Writing your first patch for Django here, and when I run PYTHONPATH=.. python runtests.py --settings=test_sqlite in the tests/, I got an error says "SyntaxError: Non-ASCII character '\xc6' in file /path/to/dir/django/tests/regressiontests/utils/jslex.py on line 26, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details". Then I open /path/to/dir/django/tests/regressiontests/utils/jslex.py and added # -*- coding: utf-8 -*- at the top fixed it.

@timgraham
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Shellbye, I'm not sure about that error, but please try using the latest version of the tutorial. To get help use the the django-core-mentorship mailing list or the #django-dev IRC channel. Thanks!

Please sign in to comment.