class documentation

class ModelAdmin(BaseModelAdmin):

Known subclasses: django.contrib.gis.admin.GeoModelAdmin, django.contrib.gis.admin.GISModelAdmin, django.contrib.auth.admin.GroupAdmin, django.contrib.auth.admin.UserAdmin, django.contrib.flatpages.admin.FlatPageAdmin, django.contrib.redirects.admin.RedirectAdmin, django.contrib.sites.admin.SiteAdmin

View In Hierarchy

Encapsulate all admin options and functionality for a given model.
Method add​_view Undocumented
Method change​_view Undocumented
Method changelist​_view The 'change list' admin view for this model.
Method delete​_model Given a model instance delete it from the database.
Method delete​_queryset Given a queryset, delete it from the database.
Method delete​_view Undocumented
Method get​_actions Return a dictionary mapping the names of all actions for this ModelAdmin to a tuple of (callable, name, description) for each action.
Method get​_changeform​_initial​_data Get the initial form data from the request's GET params.
Method get​_changelist Return the ChangeList class for use on the changelist page.
Method get​_changelist​_form Return a Form class for use in the Formset on the changelist page.
Method get​_changelist​_formset Return a FormSet class for use on the changelist page if list_editable is used.
Method get​_deleted​_objects Hook for customizing the delete process for the delete view and the "delete selected" action.
Method get​_form Return a Form class for use in the admin add view. This is used by add_view and change_view.
Method get​_formset​_kwargs Undocumented
Method get​_formsets​_with​_inlines Yield formsets and the corresponding inlines.
Method get​_inline​_instances Undocumented
Method get​_list​_display Return a sequence containing the fields to be displayed on the changelist.
Method get​_list​_display​_links Return a sequence containing the fields to be displayed as links on the changelist. The list_display parameter is the list of fields returned by get_list_display().
Method get​_list​_filter Return a sequence containing the fields to be displayed as filters in the right sidebar of the changelist page.
Method get​_list​_select​_related Return a list of fields to add to the select_related() part of the changelist items query.
Method get​_paginator Undocumented
Method get​_search​_fields Return a sequence containing the fields to be searched whenever somebody submits a search query.
Method get​_search​_results Return a tuple containing a queryset to implement the search and a boolean indicating if the results may contain duplicates.
Method get​_urls Undocumented
Method history​_view The 'history' admin view for this model.
Method message​_user Send a message to the user. The default implementation posts a message using the django.contrib.messages backend.
Method response​_add Determine the HttpResponse for the add_view stage.
Method response​_change Determine the HttpResponse for the change_view stage.
Method response​_delete Determine the HttpResponse for the delete_view stage.
Method save​_formset Given an inline formset save it to the database.
Method save​_model Given a model instance save it to the database.
Method save​_related No summary
Class Variable actions Undocumented
Class Variable actions​_on​_bottom Undocumented
Class Variable actions​_on​_top Undocumented
Class Variable actions​_selection​_counter Undocumented
Class Variable add​_form​_template Undocumented
Class Variable change​_form​_template Undocumented
Class Variable change​_list​_template Undocumented
Class Variable date​_hierarchy Undocumented
Class Variable delete​_confirmation​_template Undocumented
Class Variable delete​_selected​_confirmation​_template Undocumented
Class Variable inlines Undocumented
Class Variable list​_display Undocumented
Class Variable list​_display​_links Undocumented
Class Variable list​_editable Undocumented
Class Variable list​_filter Undocumented
Class Variable list​_max​_show​_all Undocumented
Class Variable list​_per​_page Undocumented
Class Variable list​_select​_related Undocumented
Class Variable object​_history​_template Undocumented
Class Variable popup​_response​_template Undocumented
Class Variable preserve​_filters Undocumented
Class Variable save​_as Undocumented
Class Variable save​_as​_continue Undocumented
Class Variable save​_on​_top Undocumented
Class Variable search​_fields Undocumented
Class Variable search​_help​_text Undocumented
Static Method ​_get​_action​_description Undocumented
Method __init__ Undocumented
Method __repr__ Undocumented
Method __str__ Undocumented
Method ​_changeform​_view Undocumented
Method ​_create​_formsets Helper function to generate formsets for add/change_view.
Method ​_delete​_view The 'delete' admin view for this model.
Method ​_filter​_actions​_by​_permissions Filter out any actions that the user doesn't have access to.
Method ​_get​_base​_actions Return the list of actions, prior to any request-based filtering.
Method ​_get​_edited​_object​_pks Return POST data values of list_editable primary keys.
Method ​_get​_form​_for​_get​_fields Undocumented
Method ​_get​_list​_editable​_queryset Based on POST data, return a queryset of the objects that were edited via list_editable.
Method ​_get​_obj​_does​_not​_exist​_redirect Create a message informing the user that the object doesn't exist and return a redirect to the admin index page.
Method ​_response​_post​_save Undocumented
Method action​_checkbox A list_display column containing a checkbox widget.
Method changeform​_view Undocumented
Method construct​_change​_message Construct a JSON structure describing changes from a changed object.
Method get​_action Return a given action from a parameter, which can either be a callable, or the name of a method on the ModelAdmin. Return is a tuple of (callable, name, description).
Method get​_action​_choices Return a list of choices for use in a form object. Each choice is a tuple (name, description).
Method get​_changelist​_instance Return a ChangeList instance based on request. May raise IncorrectLookupParameters.
Method get​_inline​_formsets Undocumented
Method get​_model​_perms Return a dict of all perms for this model. This dict has the keys add, change, delete, and view mapping to the True/False for each of those actions.
Method get​_object Return an instance matching the field and value provided, the primary key is used if no field is provided. Return None if no match is found or the object_id fails validation.
Method get​_preserved​_filters Return the preserved filters querystring.
Method log​_addition Log that an object has been successfully added.
Method log​_change Log that an object has been successfully changed.
Method log​_deletion Log that an object will be deleted. Note that this method must be called before the deletion.
Method render​_change​_form Undocumented
Method render​_delete​_form Undocumented
Method response​_action Handle an admin action. This is called if a request is POSTed to the changelist; it returns an HttpResponse if the action was handled, and None otherwise.
Method response​_post​_save​_add Figure out where to redirect after the 'Save' button has been pressed when adding a new object.
Method response​_post​_save​_change Figure out where to redirect after the 'Save' button has been pressed when editing an existing object.
Method save​_form Given a ModelForm return an unsaved instance. change is True if the object is being changed, and False if it's being added.
Instance Variable admin​_site Undocumented
Instance Variable model Undocumented
Instance Variable opts Undocumented
Property media Undocumented
Property urls Undocumented

Inherited from BaseModelAdmin:

Method check Undocumented
Method formfield​_for​_choice​_field Get a form Field for a database Field that has declared choices.
Method formfield​_for​_dbfield Hook for specifying the form Field instance for a given database Field instance.
Method formfield​_for​_foreignkey Get a form Field for a ForeignKey.
Method formfield​_for​_manytomany Get a form Field for a ManyToManyField.
Method get​_autocomplete​_fields Return a list of ForeignKey and/or ManyToMany fields which should use an autocomplete widget.
Method get​_empty​_value​_display Return the empty_value_display set on ModelAdmin or AdminSite.
Method get​_exclude Hook for specifying exclude.
Method get​_field​_queryset If the ModelAdmin specifies ordering, the queryset should respect that ordering. Otherwise don't specify the queryset, let the field decide (return None in that case).
Method get​_fields Hook for specifying fields.
Method get​_fieldsets Hook for specifying fieldsets.
Method get​_inlines Hook for specifying custom inlines.
Method get​_ordering Hook for specifying field ordering.
Method get​_prepopulated​_fields Hook for specifying custom prepopulated fields.
Method get​_queryset Return a QuerySet of all model instances that can be edited by the admin site. This is used by changelist_view.
Method get​_readonly​_fields Hook for specifying custom readonly fields.
Method get​_sortable​_by Hook for specifying which fields can be sorted in the changelist.
Method get​_view​_on​_site​_url Undocumented
Method has​_add​_permission Return True if the given request has permission to add an object. Can be overridden by the user in subclasses.
Method has​_change​_permission Return True if the given request has permission to change the given Django model instance, the default implementation doesn't examine the obj parameter.
Method has​_delete​_permission Return True if the given request has permission to change the given Django model instance, the default implementation doesn't examine the obj parameter.
Method has​_module​_permission Return True if the given request has any permission in the given app label.
Method has​_view​_or​_change​_permission Undocumented
Method has​_view​_permission Return True if the given request has permission to view the given Django model instance. The default implementation doesn't examine the obj parameter.
Method lookup​_allowed Undocumented
Method to​_field​_allowed Return True if the model associated with this admin should be allowed to be referenced by the specified field.
Class Variable autocomplete​_fields Undocumented
Class Variable exclude Undocumented
Class Variable fields Undocumented
Class Variable fieldsets Undocumented
Class Variable filter​_horizontal Undocumented
Class Variable filter​_vertical Undocumented
Class Variable ordering Undocumented
Class Variable prepopulated​_fields Undocumented
Class Variable radio​_fields Undocumented
Class Variable raw​_id​_fields Undocumented
Class Variable readonly​_fields Undocumented
Class Variable show​_full​_result​_count Undocumented
Class Variable sortable​_by Undocumented
Class Variable view​_on​_site Undocumented
Instance Variable formfield​_overrides Undocumented
def add_view(self, request, form_url='', extra_context=None):

Undocumented

def change_view(self, request, object_id, form_url='', extra_context=None):

Undocumented

@csrf_protect_m
def changelist_view(self, request, extra_context=None):
The 'change list' admin view for this model.
def delete_model(self, request, obj):
Given a model instance delete it from the database.
def delete_queryset(self, request, queryset):
Given a queryset, delete it from the database.
@csrf_protect_m
def delete_view(self, request, object_id, extra_context=None):

Undocumented

def get_actions(self, request):
Return a dictionary mapping the names of all actions for this ModelAdmin to a tuple of (callable, name, description) for each action.
def get_changeform_initial_data(self, request):
Get the initial form data from the request's GET params.
def get_changelist(self, request, **kwargs):
Return the ChangeList class for use on the changelist page.
def get_changelist_form(self, request, **kwargs):
Return a Form class for use in the Formset on the changelist page.
def get_changelist_formset(self, request, **kwargs):
Return a FormSet class for use on the changelist page if list_editable is used.
def get_deleted_objects(self, objs, request):
Hook for customizing the delete process for the delete view and the "delete selected" action.
def get_form(self, request, obj=None, change=False, **kwargs):
Return a Form class for use in the admin add view. This is used by add_view and change_view.
def get_formset_kwargs(self, request, obj, inline, prefix):

Undocumented

def get_formsets_with_inlines(self, request, obj=None):
Yield formsets and the corresponding inlines.
def get_inline_instances(self, request, obj=None):

Undocumented

def get_list_display(self, request):
Return a sequence containing the fields to be displayed on the changelist.
def get_list_display_links(self, request, list_display):
Return a sequence containing the fields to be displayed as links on the changelist. The list_display parameter is the list of fields returned by get_list_display().
def get_list_filter(self, request):
Return a sequence containing the fields to be displayed as filters in the right sidebar of the changelist page.
def get_list_select_related(self, request):
Return a list of fields to add to the select_related() part of the changelist items query.
def get_paginator(self, request, queryset, per_page, orphans=0, allow_empty_first_page=True):

Undocumented

def get_search_fields(self, request):
Return a sequence containing the fields to be searched whenever somebody submits a search query.
def get_search_results(self, request, queryset, search_term):
Return a tuple containing a queryset to implement the search and a boolean indicating if the results may contain duplicates.
def get_urls(self):

Undocumented

def history_view(self, request, object_id, extra_context=None):
The 'history' admin view for this model.
def message_user(self, request, message, level=messages.INFO, extra_tags='', fail_silently=False):

Send a message to the user. The default implementation posts a message using the django.contrib.messages backend.

Exposes almost the same API as messages.add_message(), but accepts the positional arguments in a different order to maintain backwards compatibility. For convenience, it accepts the level argument as a string rather than the usual level number.

def response_add(self, request, obj, post_url_continue=None):
Determine the HttpResponse for the add_view stage.
def response_change(self, request, obj):
Determine the HttpResponse for the change_view stage.
def response_delete(self, request, obj_display, obj_id):
Determine the HttpResponse for the delete_view stage.
def save_formset(self, request, form, formset, change):
Given an inline formset save it to the database.
def save_model(self, request, obj, form, change):
Given a model instance save it to the database.
def save_related(self, request, form, formsets, change):
Given the HttpRequest, the parent ModelForm instance, the list of inline formsets and a boolean value based on whether the parent is being added or changed, save the related objects to the database. Note that at this point save_form() and save_model() have already been called.
actions: list =

Undocumented

actions_on_bottom: bool =

Undocumented

actions_on_top: bool =

Undocumented

actions_selection_counter: bool =

Undocumented

add_form_template =

Undocumented

change_form_template =

Undocumented

change_list_template =

Undocumented

date_hierarchy =

Undocumented

delete_confirmation_template =

Undocumented

delete_selected_confirmation_template =

Undocumented

inlines: list =

Undocumented

list_display_links: tuple =

Undocumented

list_editable: tuple =

Undocumented

list_max_show_all: int =

Undocumented

list_per_page: int =

Undocumented

list_select_related: bool =

Undocumented

object_history_template =

Undocumented

popup_response_template =

Undocumented

preserve_filters: bool =

Undocumented

save_as: bool =

Undocumented

save_as_continue: bool =

Undocumented

save_on_top: bool =

Undocumented

search_help_text =

Undocumented

@staticmethod
def _get_action_description(func, name):

Undocumented

def __init__(self, model, admin_site):
def __repr__(self):

Undocumented

def __str__(self):

Undocumented

def _changeform_view(self, request, object_id, form_url, extra_context):

Undocumented

def _create_formsets(self, request, obj, change):
Helper function to generate formsets for add/change_view.
def _delete_view(self, request, object_id, extra_context):
The 'delete' admin view for this model.
def _filter_actions_by_permissions(self, request, actions):
Filter out any actions that the user doesn't have access to.
def _get_base_actions(self):
Return the list of actions, prior to any request-based filtering.
def _get_edited_object_pks(self, request, prefix):
Return POST data values of list_editable primary keys.
def _get_form_for_get_fields(self, request, obj):

Undocumented

def _get_list_editable_queryset(self, request, prefix):
Based on POST data, return a queryset of the objects that were edited via list_editable.
def _get_obj_does_not_exist_redirect(self, request, opts, object_id):
Create a message informing the user that the object doesn't exist and return a redirect to the admin index page.
def _response_post_save(self, request, obj):

Undocumented

@display(description=mark_safe('<input type="checkbox" id="action-toggle">'))
def action_checkbox(self, obj):
A list_display column containing a checkbox widget.
@csrf_protect_m
def changeform_view(self, request, object_id=None, form_url='', extra_context=None):

Undocumented

def construct_change_message(self, request, form, formsets, add=False):
Construct a JSON structure describing changes from a changed object.
def get_action(self, action):
Return a given action from a parameter, which can either be a callable, or the name of a method on the ModelAdmin. Return is a tuple of (callable, name, description).
def get_action_choices(self, request, default_choices=models.BLANK_CHOICE_DASH):
Return a list of choices for use in a form object. Each choice is a tuple (name, description).
def get_changelist_instance(self, request):
Return a ChangeList instance based on request. May raise IncorrectLookupParameters.
def get_inline_formsets(self, request, formsets, inline_instances, obj=None):

Undocumented

def get_model_perms(self, request):
Return a dict of all perms for this model. This dict has the keys add, change, delete, and view mapping to the True/False for each of those actions.
def get_object(self, request, object_id, from_field=None):
Return an instance matching the field and value provided, the primary key is used if no field is provided. Return None if no match is found or the object_id fails validation.
def get_preserved_filters(self, request):
Return the preserved filters querystring.
def log_addition(self, request, obj, message):

Log that an object has been successfully added.

The default implementation creates an admin LogEntry object.

def log_change(self, request, obj, message):

Log that an object has been successfully changed.

The default implementation creates an admin LogEntry object.

def log_deletion(self, request, obj, object_repr):

Log that an object will be deleted. Note that this method must be called before the deletion.

The default implementation creates an admin LogEntry object.

def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None):

Undocumented

def render_delete_form(self, request, context):

Undocumented

def response_action(self, request, queryset):
Handle an admin action. This is called if a request is POSTed to the changelist; it returns an HttpResponse if the action was handled, and None otherwise.
def response_post_save_add(self, request, obj):
Figure out where to redirect after the 'Save' button has been pressed when adding a new object.
def response_post_save_change(self, request, obj):
Figure out where to redirect after the 'Save' button has been pressed when editing an existing object.
def save_form(self, request, form, change):
Given a ModelForm return an unsaved instance. change is True if the object is being changed, and False if it's being added.
admin_site =

Undocumented

model =

Undocumented

opts =

Undocumented

@property
media =

Undocumented

@property
urls =

Undocumented