{"payload":{"allShortcutsEnabled":false,"fileTree":{"docs/ref/contrib/admin":{"items":[{"name":"_images","path":"docs/ref/contrib/admin/_images","contentType":"directory"},{"name":"actions.txt","path":"docs/ref/contrib/admin/actions.txt","contentType":"file"},{"name":"admindocs.txt","path":"docs/ref/contrib/admin/admindocs.txt","contentType":"file"},{"name":"index.txt","path":"docs/ref/contrib/admin/index.txt","contentType":"file"}],"totalCount":4},"docs/ref/contrib":{"items":[{"name":"admin","path":"docs/ref/contrib/admin","contentType":"directory"},{"name":"comments","path":"docs/ref/contrib/comments","contentType":"directory"},{"name":"formtools","path":"docs/ref/contrib/formtools","contentType":"directory"},{"name":"gis","path":"docs/ref/contrib/gis","contentType":"directory"},{"name":"auth.txt","path":"docs/ref/contrib/auth.txt","contentType":"file"},{"name":"contenttypes.txt","path":"docs/ref/contrib/contenttypes.txt","contentType":"file"},{"name":"csrf.txt","path":"docs/ref/contrib/csrf.txt","contentType":"file"},{"name":"flatpages.txt","path":"docs/ref/contrib/flatpages.txt","contentType":"file"},{"name":"humanize.txt","path":"docs/ref/contrib/humanize.txt","contentType":"file"},{"name":"index.txt","path":"docs/ref/contrib/index.txt","contentType":"file"},{"name":"messages.txt","path":"docs/ref/contrib/messages.txt","contentType":"file"},{"name":"redirects.txt","path":"docs/ref/contrib/redirects.txt","contentType":"file"},{"name":"sitemaps.txt","path":"docs/ref/contrib/sitemaps.txt","contentType":"file"},{"name":"sites.txt","path":"docs/ref/contrib/sites.txt","contentType":"file"},{"name":"staticfiles.txt","path":"docs/ref/contrib/staticfiles.txt","contentType":"file"},{"name":"syndication.txt","path":"docs/ref/contrib/syndication.txt","contentType":"file"},{"name":"webdesign.txt","path":"docs/ref/contrib/webdesign.txt","contentType":"file"}],"totalCount":17},"docs/ref":{"items":[{"name":"class-based-views","path":"docs/ref/class-based-views","contentType":"directory"},{"name":"contrib","path":"docs/ref/contrib","contentType":"directory"},{"name":"files","path":"docs/ref/files","contentType":"directory"},{"name":"forms","path":"docs/ref/forms","contentType":"directory"},{"name":"models","path":"docs/ref/models","contentType":"directory"},{"name":"templates","path":"docs/ref/templates","contentType":"directory"},{"name":"clickjacking.txt","path":"docs/ref/clickjacking.txt","contentType":"file"},{"name":"databases.txt","path":"docs/ref/databases.txt","contentType":"file"},{"name":"django-admin.txt","path":"docs/ref/django-admin.txt","contentType":"file"},{"name":"exceptions.txt","path":"docs/ref/exceptions.txt","contentType":"file"},{"name":"index.txt","path":"docs/ref/index.txt","contentType":"file"},{"name":"middleware.txt","path":"docs/ref/middleware.txt","contentType":"file"},{"name":"request-response.txt","path":"docs/ref/request-response.txt","contentType":"file"},{"name":"settings.txt","path":"docs/ref/settings.txt","contentType":"file"},{"name":"signals.txt","path":"docs/ref/signals.txt","contentType":"file"},{"name":"template-response.txt","path":"docs/ref/template-response.txt","contentType":"file"},{"name":"unicode.txt","path":"docs/ref/unicode.txt","contentType":"file"},{"name":"urlresolvers.txt","path":"docs/ref/urlresolvers.txt","contentType":"file"},{"name":"urls.txt","path":"docs/ref/urls.txt","contentType":"file"},{"name":"utils.txt","path":"docs/ref/utils.txt","contentType":"file"},{"name":"validators.txt","path":"docs/ref/validators.txt","contentType":"file"},{"name":"views.txt","path":"docs/ref/views.txt","contentType":"file"}],"totalCount":22},"docs":{"items":[{"name":"_ext","path":"docs/_ext","contentType":"directory"},{"name":"_theme","path":"docs/_theme","contentType":"directory"},{"name":"faq","path":"docs/faq","contentType":"directory"},{"name":"howto","path":"docs/howto","contentType":"directory"},{"name":"internals","path":"docs/internals","contentType":"directory"},{"name":"intro","path":"docs/intro","contentType":"directory"},{"name":"man","path":"docs/man","contentType":"directory"},{"name":"misc","path":"docs/misc","contentType":"directory"},{"name":"ref","path":"docs/ref","contentType":"directory"},{"name":"releases","path":"docs/releases","contentType":"directory"},{"name":"topics","path":"docs/topics","contentType":"directory"},{"name":"Makefile","path":"docs/Makefile","contentType":"file"},{"name":"README","path":"docs/README","contentType":"file"},{"name":"conf.py","path":"docs/conf.py","contentType":"file"},{"name":"contents.txt","path":"docs/contents.txt","contentType":"file"},{"name":"glossary.txt","path":"docs/glossary.txt","contentType":"file"},{"name":"index.txt","path":"docs/index.txt","contentType":"file"},{"name":"make.bat","path":"docs/make.bat","contentType":"file"}],"totalCount":18},"":{"items":[{"name":".tx","path":".tx","contentType":"directory"},{"name":"django","path":"django","contentType":"directory"},{"name":"docs","path":"docs","contentType":"directory"},{"name":"extras","path":"extras","contentType":"directory"},{"name":"scripts","path":"scripts","contentType":"directory"},{"name":"tests","path":"tests","contentType":"directory"},{"name":".gitattributes","path":".gitattributes","contentType":"file"},{"name":".gitignore","path":".gitignore","contentType":"file"},{"name":".hgignore","path":".hgignore","contentType":"file"},{"name":"AUTHORS","path":"AUTHORS","contentType":"file"},{"name":"CONTRIBUTING.rst","path":"CONTRIBUTING.rst","contentType":"file"},{"name":"INSTALL","path":"INSTALL","contentType":"file"},{"name":"LICENSE","path":"LICENSE","contentType":"file"},{"name":"MANIFEST.in","path":"MANIFEST.in","contentType":"file"},{"name":"README.rst","path":"README.rst","contentType":"file"},{"name":"setup.cfg","path":"setup.cfg","contentType":"file"},{"name":"setup.py","path":"setup.py","contentType":"file"}],"totalCount":17}},"fileTreeProcessingTime":97.57784799999999,"foldersToFetch":[],"repo":{"id":4164482,"defaultBranch":"main","name":"django","ownerLogin":"django","currentUserCanPush":false,"isFork":false,"isEmpty":false,"createdAt":"2012-04-28T02:47:18.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/27804?v=4","public":true,"private":false,"isOrgOwned":true},"symbolsExpanded":false,"treeExpanded":true,"refInfo":{"name":"f026a519aea8f3ea7ca339bfbbb007e1ee0068b0","listCacheKey":"v0:1709542684.0","canEdit":false,"refType":"tree","currentOid":"f026a519aea8f3ea7ca339bfbbb007e1ee0068b0"},"path":"docs/ref/contrib/admin/index.txt","currentUser":null,"blob":{"rawLines":["=====================","The Django admin site","=====================","",".. module:: django.contrib.admin"," :synopsis: Django's admin site.","","One of the most powerful parts of Django is the automatic admin interface. It","reads metadata in your model to provide a powerful and production-ready","interface that content producers can immediately use to start adding content to","the site. In this document, we discuss how to activate, use and customize","Django's admin interface.","","Overview","========","","The admin is enabled in the default project template used by",":djadmin:`startproject`.","",".. versionchanged:: 1.6",""," In previous versions, the admin wasn't enabled by default.","","For reference, here are the requirements:","","1. Add ``'django.contrib.admin'`` to your :setting:`INSTALLED_APPS`"," setting.","","2. The admin has four dependencies - :mod:`django.contrib.auth`,"," :mod:`django.contrib.contenttypes`,"," :mod:`django.contrib.messages` and"," :mod:`django.contrib.sessions`. If these applications are not"," in your :setting:`INSTALLED_APPS` list, add them.","","3. Add ``django.contrib.messages.context_processors.messages`` to"," :setting:`TEMPLATE_CONTEXT_PROCESSORS` as well as"," :class:`django.contrib.auth.middleware.AuthenticationMiddleware` and"," :class:`django.contrib.messages.middleware.MessageMiddleware` to"," :setting:`MIDDLEWARE_CLASSES`. (These are all active by default, so"," you only need to do this if you've manually tweaked the settings.)","","4. Determine which of your application's models should be editable in the"," admin interface.","","5. For each of those models, optionally create a ``ModelAdmin`` class that"," encapsulates the customized admin functionality and options for that"," particular model.","","6. Instantiate an ``AdminSite`` and tell it about each of your models and"," ``ModelAdmin`` classes.","","7. Hook the ``AdminSite`` instance into your URLconf.","","After you've taken these steps, you'll be able to use your Django admin site","by visiting the URL you hooked it into (``/admin/``, by default).","","Other topics","------------","",".. toctree::"," :maxdepth: 1",""," actions"," admindocs","",".. seealso::",""," For information about serving the static files (images, JavaScript, and"," CSS) associated with the admin in production, see :ref:`serving-files`.",""," Having problems? Try :doc:`/faq/admin`.","","``ModelAdmin`` objects","======================","",".. class:: ModelAdmin",""," The ``ModelAdmin`` class is the representation of a model in the admin"," interface. These are stored in a file named ``admin.py`` in your"," application. Let's take a look at a very simple example of"," the ``ModelAdmin``::",""," from django.contrib import admin"," from myproject.myapp.models import Author",""," class AuthorAdmin(admin.ModelAdmin):"," pass"," admin.site.register(Author, AuthorAdmin)",""," .. admonition:: Do you need a ``ModelAdmin`` object at all?",""," In the preceding example, the ``ModelAdmin`` class doesn't define any"," custom values (yet). As a result, the default admin interface will be"," provided. If you are happy with the default admin interface, you don't"," need to define a ``ModelAdmin`` object at all -- you can register the"," model class without providing a ``ModelAdmin`` description. The"," preceding example could be simplified to::",""," from django.contrib import admin"," from myproject.myapp.models import Author",""," admin.site.register(Author)","","``ModelAdmin`` options","----------------------","","The ``ModelAdmin`` is very flexible. It has several options for dealing with","customizing the interface. All options are defined on the ``ModelAdmin``","subclass::",""," class AuthorAdmin(admin.ModelAdmin):"," date_hierarchy = 'pub_date'","",".. attribute:: ModelAdmin.actions",""," A list of actions to make available on the change list page. See"," :doc:`/ref/contrib/admin/actions` for details.","",".. attribute:: ModelAdmin.actions_on_top",".. attribute:: ModelAdmin.actions_on_bottom",""," Controls where on the page the actions bar appears. By default, the admin"," changelist displays actions at the top of the page (``actions_on_top = True;"," actions_on_bottom = False``).","",".. attribute:: ModelAdmin.actions_selection_counter",""," Controls whether a selection counter is displayed next to the action dropdown."," By default, the admin changelist will display it"," (``actions_selection_counter = True``).","",".. attribute:: ModelAdmin.date_hierarchy",""," Set ``date_hierarchy`` to the name of a ``DateField`` or ``DateTimeField``"," in your model, and the change list page will include a date-based drilldown"," navigation by that field.",""," Example::",""," date_hierarchy = 'pub_date'",""," This will intelligently populate itself based on available data,"," e.g. if all the dates are in one month, it'll show the day-level"," drill-down only.",""," .. note::",""," ``date_hierarchy`` uses :meth:`QuerySet.datetimes()"," ` internally. Please refer"," to its documentation for some caveats when time zone support is"," enabled (:setting:`USE_TZ = True `).","",".. attribute:: ModelAdmin.exclude",""," This attribute, if given, should be a list of field names to exclude from"," the form.",""," For example, let's consider the following model::",""," class Author(models.Model):"," name = models.CharField(max_length=100)"," title = models.CharField(max_length=3)"," birth_date = models.DateField(blank=True, null=True)",""," If you want a form for the ``Author`` model that includes only the ``name``"," and ``title`` fields, you would specify ``fields`` or ``exclude`` like"," this::",""," class AuthorAdmin(admin.ModelAdmin):"," fields = ('name', 'title')",""," class AuthorAdmin(admin.ModelAdmin):"," exclude = ('birth_date',)",""," Since the Author model only has three fields, ``name``, ``title``, and"," ``birth_date``, the forms resulting from the above declarations will"," contain exactly the same fields.","",".. attribute:: ModelAdmin.fields",""," If you need to achieve simple changes in the layout of fields in the forms"," of the \"add\" and \"change\" pages like only showing a subset of the available"," fields, modifying their order or grouping them in rows you can use the"," ``fields`` option (for more complex layout needs see the"," :attr:`~ModelAdmin.fieldsets` option described in the next section). For"," example, you could define a simpler version of the admin form for the"," :class:`django.contrib.flatpages.models.FlatPage` model as follows::",""," class FlatPageAdmin(admin.ModelAdmin):"," fields = ('url', 'title', 'content')",""," In the above example, only the fields ``url``, ``title`` and ``content``"," will be displayed, sequentially, in the form. ``fields`` can contain"," values defined in :attr:`ModelAdmin.readonly_fields` to be displayed as"," read-only.",""," The ``fields`` option, unlike :attr:`~ModelAdmin.list_display`, may only"," contain names of fields on the model or the form specified by"," :attr:`~ModelAdmin.form`. It may contain callables only if they are listed"," in :attr:`~ModelAdmin.readonly_fields`.",""," To display multiple fields on the same line, wrap those fields in their own"," tuple. In this example, the ``url`` and ``title`` fields will display on the"," same line and the ``content`` field will be displayed below them in its"," own line::",""," class FlatPageAdmin(admin.ModelAdmin):"," fields = (('url', 'title'), 'content')",""," .. admonition:: Note",""," This ``fields`` option should not be confused with the ``fields``"," dictionary key that is within the :attr:`~ModelAdmin.fieldsets` option,"," as described in the next section.",""," If neither ``fields`` nor :attr:`~ModelAdmin.fieldsets` options are present,"," Django will default to displaying each field that isn't an ``AutoField`` and"," has ``editable=True``, in a single fieldset, in the same order as the fields"," are defined in the model.","",".. attribute:: 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"," ``
`` on the admin form page. (A ``
`` 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 full example, taken from the"," :class:`django.contrib.flatpages.models.FlatPage` model::",""," class FlatPageAdmin(admin.ModelAdmin):"," fieldsets = ("," (None, {"," 'fields': ('url', 'title', 'content', 'sites')"," }),"," ('Advanced options', {"," 'classes': ('collapse',),"," 'fields': ('enable_comments', 'registration_required', 'template_name')"," }),"," )",""," This results in an admin page that looks like:",""," .. image:: _images/flatfiles_admin.png",""," If neither ``fieldsets`` nor :attr:`~ModelAdmin.fields` options are present,"," Django will default to displaying each field that isn't an ``AutoField`` and"," has ``editable=True``, in a single fieldset, in the same order as the fields"," are defined in the model.",""," The ``field_options`` dictionary can have the following keys:",""," * ``fields``"," A tuple of field names to display in this fieldset. This key is"," required.",""," Example::",""," {"," 'fields': ('first_name', 'last_name', 'address', 'city', 'state'),"," }",""," As with the :attr:`~ModelAdmin.fields` option, to display multiple"," fields on the same line, wrap those fields in their own tuple. In this"," example, the ``first_name`` and ``last_name`` fields will display on"," the same line::",""," {"," 'fields': (('first_name', 'last_name'), 'address', 'city', 'state'),"," }",""," ``fields`` can contain values defined in"," :attr:`~ModelAdmin.readonly_fields` to be displayed as read-only.",""," If you add the name of a callable to ``fields``, the same rule applies"," as with the :attr:`~ModelAdmin.fields` option: the callable must be"," listed in :attr:`~ModelAdmin.readonly_fields`.",""," * ``classes``"," A list containing extra CSS classes to apply to the fieldset.",""," Example::",""," {"," 'classes': ('wide', 'extrapretty'),"," }",""," Two useful classes defined by the default admin site stylesheet are"," ``collapse`` and ``wide``. Fieldsets with the ``collapse`` style"," will be initially collapsed in the admin and replaced with a small"," \"click to expand\" link. Fieldsets with the ``wide`` style will be"," given extra horizontal space.",""," * ``description``"," A string of optional extra text to be displayed at the top of each"," fieldset, under the heading of the fieldset.",""," Note that this value is *not* HTML-escaped when it's displayed in"," the admin interface. This lets you include HTML if you so desire."," Alternatively you can use plain text and"," ``django.utils.html.escape()`` to escape any HTML special"," characters.","",".. attribute:: ModelAdmin.filter_horizontal",""," By default, a :class:`~django.db.models.ManyToManyField` is displayed in"," the admin site with a ``