admin.ModelAdmin.get_changelist()

ModelAdmin.get_changelist(request, **kwargs) [source] 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.

admin.ModelAdmin.get_changelist_form()

ModelAdmin.get_changelist_form(request, **kwargs) [source] Returns a ModelForm class for use in the Formset on the changelist page. To use a custom form, for example: from django import forms class MyForm(forms.ModelForm): pass class MyModelAdmin(admin.ModelAdmin): def get_changelist_form(self, request, **kwargs): return MyForm Note If you define the Meta.model attribute on a ModelForm, you must also define the Meta.fields attribute (or the Meta.exclude attribute). Howeve

admin.ModelAdmin.get_actions()

ModelAdmin.get_actions(request) [source] Finally, you can conditionally enable or disable actions on a per-request (and hence per-user basis) by overriding ModelAdmin.get_actions(). This returns a dictionary of actions allowed. The keys are action names, and the values are (function, name, short_description) tuples. Most of the time you’ll use this method to conditionally remove actions from the list gathered by the superclass. For example, if I only wanted users whose names begin with ‘J’ t

admin.ModelAdmin.formfield_overrides

ModelAdmin.formfield_overrides This provides a quick-and-dirty way to override some of the Field options for use in the admin. formfield_overrides is a dictionary mapping a field class to a dict of arguments to pass to the field at construction time. Since that’s a bit abstract, let’s look at a concrete example. The most common use of formfield_overrides is to add a custom widget for a certain type of field. So, imagine we’ve written a RichTextEditorWidget that we’d like to use for large tex

admin.ModelAdmin.formfield_for_foreignkey()

ModelAdmin.formfield_for_foreignkey(db_field, request, **kwargs) The formfield_for_foreignkey method on a ModelAdmin allows you to override the default formfield for a foreign keys field. For example, to return a subset of objects for this foreign key field based on the user: class MyModelAdmin(admin.ModelAdmin): def formfield_for_foreignkey(self, db_field, request, **kwargs): if db_field.name == "car": kwargs["queryset"] = Car.objects.filter(owner=request.user)

admin.ModelAdmin.formfield_for_manytomany()

ModelAdmin.formfield_for_manytomany(db_field, request, **kwargs) Like the formfield_for_foreignkey method, the formfield_for_manytomany method can be overridden to change the default formfield for a many to many field. For example, if an owner can own multiple cars and cars can belong to multiple owners – a many to many relationship – you could filter the Car foreign key field to only display the cars owned by the User: class MyModelAdmin(admin.ModelAdmin): def formfield_for_manytomany(s

admin.ModelAdmin.formfield_for_choice_field()

ModelAdmin.formfield_for_choice_field(db_field, request, **kwargs) Like the formfield_for_foreignkey and formfield_for_manytomany methods, the formfield_for_choice_field method can be overridden to change the default formfield for a field that has declared choices. For example, if the choices available to a superuser should be different than those available to regular staff, you could proceed as follows: class MyModelAdmin(admin.ModelAdmin): def formfield_for_choice_field(self, db_field,

admin.ModelAdmin.form

ModelAdmin.form By default a ModelForm is dynamically created for your model. It is used to create the form presented on both the add/change pages. You can easily provide your own ModelForm to override any default form behavior on the add/change pages. Alternatively, you can customize the default form rather than specifying an entirely new one by using the ModelAdmin.get_form() method. For an example see the section Adding custom validation to the admin. Note If you define the Meta.model at

admin.ModelAdmin.fieldsets

ModelAdmin.fieldsets Set fieldsets to control the layout of admin “add” and “change” pages. fieldsets is a list of two-tuples, in which each two-tuple represents a <fieldset> on the admin form page. (A <fieldset> is a “section” of the form.) The two-tuples are in the format (name, field_options), where name is a string representing the title of the fieldset and field_options is a dictionary of information about the fieldset, including a list of fields to be displayed in it. A ful

admin.ModelAdmin.filter_vertical

ModelAdmin.filter_vertical Same as filter_horizontal, but uses a vertical display of the filter interface with the box of unselected options appearing above the box of selected options.