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_changeform_initial_data()

ModelAdmin.get_changeform_initial_data(request) [source] A hook for the initial data on admin change forms. By default, fields are given initial values from GET parameters. For instance, ?name=initial_value will set the name field’s initial value to be initial_value. This method should return a dictionary in the form {'fieldname': 'fieldval'}: def get_changeform_initial_data(self, request): return {'name': 'custom_initial_value'}

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_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_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_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.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.

admin.ModelAdmin.filter_horizontal

ModelAdmin.filter_horizontal By default, a ManyToManyField is displayed in the admin site with a <select multiple>. However, multiple-select boxes can be difficult to use when selecting many items. Adding a ManyToManyField to this list will instead use a nifty unobtrusive JavaScript “filter” interface that allows searching within the options. The unselected and selected options appear in two boxes side by side. See filter_vertical to use a vertical interface.