{"title":"Writing your first Django app, part 2","version":"1.8","locale":"en","docname":"intro/tutorial02","url":"/en/1.8/intro/tutorial02/","canonical":"https://djangodocs.dev/en/1.8/intro/tutorial02/","summary":"This tutorial begins where Tutorial 1 left off. We’re continuing the Web-poll application and will focus on Django’s automatically-generated admin site.","html":"<h1>Writing your first Django app, part 2<a class=\"heading-anchor\" href=\"#writing-your-first-django-app-part-2\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>This tutorial begins where <a class=\"reference internal\" href=\"/en/1.8/intro/tutorial01/\"><span class=\"doc\">Tutorial 1</span></a> left off. We’re\ncontinuing the Web-poll application and will focus on Django’s\nautomatically-generated admin site.</p>\n<aside class=\"admonition-philosophy admonition\" role=\"note\">\n<p class=\"admonition-title\">Philosophy</p>\n<p>Generating admin sites for your staff or clients to add, change and delete\ncontent is tedious work that doesn’t require much creativity. For that\nreason, Django entirely automates creation of admin interfaces for models.</p>\n<p>Django was written in a newsroom environment, with a very clear separation\nbetween “content publishers” and the “public” site. Site managers use the\nsystem to add news stories, events, sports scores, etc., and that content is\ndisplayed on the public site. Django solves the problem of creating a\nunified interface for site administrators to edit content.</p>\n<p>The admin isn’t intended to be used by site visitors. It’s for site\nmanagers.</p>\n</aside>\n<section id=\"creating-an-admin-user\">\n<h2>Creating an admin user<a class=\"heading-anchor\" href=\"#creating-an-admin-user\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>First we’ll need to create a user who can login to the admin site. Run the\nfollowing command:</p>\n<div class=\"code-block\" data-language=\"console\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code><span class=\"gp\">$ </span>python manage.py createsuperuser\n</code></pre></div>\n<p>Enter your desired username and press enter.</p>\n<div class=\"code-block\" data-language=\"text\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Text</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Text code\"><code>Username: admin\n</code></pre></div>\n<p>You will then be prompted for your desired email address:</p>\n<div class=\"code-block\" data-language=\"text\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Text</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Text code\"><code>Email address: admin@example.com\n</code></pre></div>\n<p>The final step is to enter your password. You will be asked to enter your\npassword twice, the second time as a confirmation of the first.</p>\n<div class=\"code-block\" data-language=\"text\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Text</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Text code\"><code>Password: **********\nPassword (again): *********\nSuperuser created successfully.\n</code></pre></div>\n</section>\n<section id=\"start-the-development-server\">\n<h2>Start the development server<a class=\"heading-anchor\" href=\"#start-the-development-server\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The Django admin site is activated by default. Let’s start the development\nserver and explore it.</p>\n<p>Recall from Tutorial 1 that you start the development server like so:</p>\n<div class=\"code-block\" data-language=\"console\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code><span class=\"gp\">$ </span>python manage.py runserver\n</code></pre></div>\n<p>Now, open a Web browser and go to “/admin/” on your local domain – e.g.,\n<a class=\"reference external\" href=\"http://127.0.0.1:8000/admin/\">http://127.0.0.1:8000/admin/</a>. You should see the admin’s login screen:</p>\n<img alt=\"Django admin login screen\" src=\"/en/1.8/_images/admin01.png\" />\n<p>Since <a class=\"reference internal\" href=\"/en/1.8/topics/i18n/translation/\"><span class=\"doc\">translation</span></a> is turned on by default,\nthe login screen may be displayed in your own language, depending on your\nbrowser’s settings and on whether Django has a translation for this language.</p>\n<aside class=\"admonition-doesn-t-match-what-you-see admonition\" role=\"note\">\n<p class=\"admonition-title\">Doesn’t match what you see?</p>\n<p>If at this point, instead of the above login page, you get an error\npage reporting something like:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"ne\">ImportError</span> at <span class=\"o\">/</span>admin<span class=\"o\">/</span>\ncannot <span class=\"kn\">import</span> <span class=\"nn\">name</span> patterns\n<span class=\"o\">...</span>\n</code></pre></div>\n<p>then you’re probably using a version of Django that doesn’t match this\ntutorial version. You’ll want to either switch to the older tutorial or the\nnewer Django version.</p>\n</aside>\n</section>\n<section id=\"enter-the-admin-site\">\n<h2>Enter the admin site<a class=\"heading-anchor\" href=\"#enter-the-admin-site\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Now, try logging in with the superuser account you created in the previous step.\nYou should see the Django admin index page:</p>\n<img alt=\"Django admin index page\" src=\"/en/1.8/_images/admin02.png\" />\n<p>You should see a few types of editable content: groups and users. They are\nprovided by <a class=\"reference internal\" href=\"/en/1.8/topics/auth/#module-django.contrib.auth\" title=\"django.contrib.auth: Django's authentication framework.\"><code class=\"xref py py-mod docutils literal notranslate\">django.contrib.auth</code></a>, the authentication framework shipped\nby Django.</p>\n</section>\n<section id=\"make-the-poll-app-modifiable-in-the-admin\">\n<h2>Make the poll app modifiable in the admin<a class=\"heading-anchor\" href=\"#make-the-poll-app-modifiable-in-the-admin\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>But where’s our poll app? It’s not displayed on the admin index page.</p>\n<p>Just one thing to do: we need to tell the admin that <code class=\"docutils literal notranslate\">Question</code>\nobjects have an admin interface. To do this, open the <code class=\"file docutils literal notranslate\">polls/admin.py</code>\nfile, and edit it to look like this:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"default\"><figcaption class=\"code-block-caption\"><code>polls/admin.py</code></figcaption><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"polls/admin.py\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.contrib</span> <span class=\"kn\">import</span> admin\n\n<span class=\"kn\">from</span> <span class=\"nn\">.models</span> <span class=\"kn\">import</span> Question\n\nadmin<span class=\"o\">.</span>site<span class=\"o\">.</span>register<span class=\"p\">(</span>Question<span class=\"p\">)</span>\n</code></pre></figure>\n</section>\n<section id=\"explore-the-free-admin-functionality\">\n<h2>Explore the free admin functionality<a class=\"heading-anchor\" href=\"#explore-the-free-admin-functionality\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Now that we’ve registered <code class=\"docutils literal notranslate\">Question</code>, Django knows that it should be displayed on\nthe admin index page:</p>\n<img alt=\"Django admin index page, now with polls displayed\" src=\"/en/1.8/_images/admin03t.png\" />\n<p>Click “Questions”. Now you’re at the “change list” page for questions. This page\ndisplays all the questions in the database and lets you choose one to change it.\nThere’s the “What’s up?” question we created in the first tutorial:</p>\n<img alt=\"Polls change list page\" src=\"/en/1.8/_images/admin04t.png\" />\n<p>Click the “What’s up?” question to edit it:</p>\n<img alt=\"Editing form for question object\" src=\"/en/1.8/_images/admin05t.png\" />\n<p>Things to note here:</p>\n<ul class=\"simple\">\n<li><p>The form is automatically generated from the <code class=\"docutils literal notranslate\">Question</code> model.</p></li>\n<li><p>The different model field types (<a class=\"reference internal\" href=\"/en/1.8/ref/models/fields/#django.db.models.DateTimeField\" title=\"django.db.models.DateTimeField\"><code class=\"xref py py-class docutils literal notranslate\">DateTimeField</code></a>,\n<a class=\"reference internal\" href=\"/en/1.8/ref/models/fields/#django.db.models.CharField\" title=\"django.db.models.CharField\"><code class=\"xref py py-class docutils literal notranslate\">CharField</code></a>) correspond to the appropriate HTML\ninput widget. Each type of field knows how to display itself in the Django\nadmin.</p></li>\n<li><p>Each <a class=\"reference internal\" href=\"/en/1.8/ref/models/fields/#django.db.models.DateTimeField\" title=\"django.db.models.DateTimeField\"><code class=\"xref py py-class docutils literal notranslate\">DateTimeField</code></a> gets free JavaScript\nshortcuts. Dates get a “Today” shortcut and calendar popup, and times get\na “Now” shortcut and a convenient popup that lists commonly entered times.</p></li>\n</ul>\n<p>The bottom part of the page gives you a couple of options:</p>\n<ul class=\"simple\">\n<li><p>Save – Saves changes and returns to the change-list page for this type of\nobject.</p></li>\n<li><p>Save and continue editing – Saves changes and reloads the admin page for\nthis object.</p></li>\n<li><p>Save and add another – Saves changes and loads a new, blank form for this\ntype of object.</p></li>\n<li><p>Delete – Displays a delete confirmation page.</p></li>\n</ul>\n<p>If the value of “Date published” doesn’t match the time when you created the\nquestion in Tutorial 1, it probably means you forgot to set the correct value for\nthe <a class=\"reference internal\" href=\"/en/1.8/ref/settings/#std-setting-TIME_ZONE\"><code class=\"xref std std-setting docutils literal notranslate\">TIME_ZONE</code></a> setting. Change it, reload the page and check that\nthe correct value appears.</p>\n<p>Change the “Date published” by clicking the “Today” and “Now” shortcuts. Then\nclick “Save and continue editing.” Then click “History” in the upper right.\nYou’ll see a page listing all changes made to this object via the Django admin,\nwith the timestamp and username of the person who made the change:</p>\n<img alt=\"History page for question object\" src=\"/en/1.8/_images/admin06t.png\" />\n</section>\n<section id=\"customize-the-admin-form\">\n<h2>Customize the admin form<a class=\"heading-anchor\" href=\"#customize-the-admin-form\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Take a few minutes to marvel at all the code you didn’t have to write. By\nregistering the <code class=\"docutils literal notranslate\">Question</code> model with <code class=\"docutils literal notranslate\">admin.site.register(Question)</code>,\nDjango was able to construct a default form representation. Often, you’ll want\nto customize how the admin form looks and works. You’ll do this by telling\nDjango the options you want when you register the object.</p>\n<p>Let’s see how this works by re-ordering the fields on the edit form. Replace\nthe <code class=\"docutils literal notranslate\">admin.site.register(Question)</code> line with:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"default\"><figcaption class=\"code-block-caption\"><code>polls/admin.py</code></figcaption><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"polls/admin.py\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.contrib</span> <span class=\"kn\">import</span> admin\n\n<span class=\"kn\">from</span> <span class=\"nn\">.models</span> <span class=\"kn\">import</span> Question\n\n\n<span class=\"k\">class</span> <span class=\"nc\">QuestionAdmin</span><span class=\"p\">(</span>admin<span class=\"o\">.</span>ModelAdmin<span class=\"p\">):</span>\n    fields <span class=\"o\">=</span> <span class=\"p\">[</span><span class=\"s1\">&#39;pub_date&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;question_text&#39;</span><span class=\"p\">]</span>\n\nadmin<span class=\"o\">.</span>site<span class=\"o\">.</span>register<span class=\"p\">(</span>Question<span class=\"p\">,</span> QuestionAdmin<span class=\"p\">)</span>\n</code></pre></figure>\n<p>You’ll follow this pattern – create a model admin object, then pass it as the\nsecond argument to <code class=\"docutils literal notranslate\">admin.site.register()</code> – any time you need to change the\nadmin options for an object.</p>\n<p>This particular change above makes the “Publication date” come before the\n“Question” field:</p>\n<img alt=\"Fields have been reordered\" src=\"/en/1.8/_images/admin07.png\" />\n<p>This isn’t impressive with only two fields, but for admin forms with dozens\nof fields, choosing an intuitive order is an important usability detail.</p>\n<p>And speaking of forms with dozens of fields, you might want to split the form\nup into fieldsets:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"default\"><figcaption class=\"code-block-caption\"><code>polls/admin.py</code></figcaption><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"polls/admin.py\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.contrib</span> <span class=\"kn\">import</span> admin\n\n<span class=\"kn\">from</span> <span class=\"nn\">.models</span> <span class=\"kn\">import</span> Question\n\n\n<span class=\"k\">class</span> <span class=\"nc\">QuestionAdmin</span><span class=\"p\">(</span>admin<span class=\"o\">.</span>ModelAdmin<span class=\"p\">):</span>\n    fieldsets <span class=\"o\">=</span> <span class=\"p\">[</span>\n        <span class=\"p\">(</span><span class=\"kc\">None</span><span class=\"p\">,</span>               <span class=\"p\">{</span><span class=\"s1\">&#39;fields&#39;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s1\">&#39;question_text&#39;</span><span class=\"p\">]}),</span>\n        <span class=\"p\">(</span><span class=\"s1\">&#39;Date information&#39;</span><span class=\"p\">,</span> <span class=\"p\">{</span><span class=\"s1\">&#39;fields&#39;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s1\">&#39;pub_date&#39;</span><span class=\"p\">]}),</span>\n    <span class=\"p\">]</span>\n\nadmin<span class=\"o\">.</span>site<span class=\"o\">.</span>register<span class=\"p\">(</span>Question<span class=\"p\">,</span> QuestionAdmin<span class=\"p\">)</span>\n</code></pre></figure>\n<p>The first element of each tuple in\n<a class=\"reference internal\" href=\"/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.fieldsets\" title=\"django.contrib.admin.ModelAdmin.fieldsets\"><code class=\"xref py py-attr docutils literal notranslate\">fieldsets</code></a> is the title of the fieldset.\nHere’s what our form looks like now:</p>\n<img alt=\"Form has fieldsets now\" src=\"/en/1.8/_images/admin08t.png\" />\n<p>You can assign arbitrary HTML classes to each fieldset. Django provides a\n<code class=\"docutils literal notranslate\">&quot;collapse&quot;</code> class that displays a particular fieldset initially collapsed.\nThis is useful when you have a long form that contains a number of fields that\naren’t commonly used:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"default\"><figcaption class=\"code-block-caption\"><code>polls/admin.py</code></figcaption><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"polls/admin.py\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.contrib</span> <span class=\"kn\">import</span> admin\n\n<span class=\"kn\">from</span> <span class=\"nn\">.models</span> <span class=\"kn\">import</span> Question\n\n\n<span class=\"k\">class</span> <span class=\"nc\">QuestionAdmin</span><span class=\"p\">(</span>admin<span class=\"o\">.</span>ModelAdmin<span class=\"p\">):</span>\n    fieldsets <span class=\"o\">=</span> <span class=\"p\">[</span>\n        <span class=\"p\">(</span><span class=\"kc\">None</span><span class=\"p\">,</span>               <span class=\"p\">{</span><span class=\"s1\">&#39;fields&#39;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s1\">&#39;question_text&#39;</span><span class=\"p\">]}),</span>\n        <span class=\"p\">(</span><span class=\"s1\">&#39;Date information&#39;</span><span class=\"p\">,</span> <span class=\"p\">{</span><span class=\"s1\">&#39;fields&#39;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s1\">&#39;pub_date&#39;</span><span class=\"p\">],</span> <span class=\"s1\">&#39;classes&#39;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s1\">&#39;collapse&#39;</span><span class=\"p\">]}),</span>\n    <span class=\"p\">]</span>\n\nadmin<span class=\"o\">.</span>site<span class=\"o\">.</span>register<span class=\"p\">(</span>Question<span class=\"p\">,</span> QuestionAdmin<span class=\"p\">)</span>\n</code></pre></figure>\n<img alt=\"Fieldset is initially collapsed\" src=\"/en/1.8/_images/admin09.png\" />\n</section>\n<section id=\"adding-related-objects\">\n<h2>Adding related objects<a class=\"heading-anchor\" href=\"#adding-related-objects\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>OK, we have our Question admin page. But a <code class=\"docutils literal notranslate\">Question</code> has multiple <code class=\"docutils literal notranslate\">Choices</code>, and\nthe admin page doesn’t display choices.</p>\n<p>Yet.</p>\n<p>There are two ways to solve this problem. The first is to register <code class=\"docutils literal notranslate\">Choice</code>\nwith the admin just as we did with <code class=\"docutils literal notranslate\">Question</code>. That’s easy:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"default\"><figcaption class=\"code-block-caption\"><code>polls/admin.py</code></figcaption><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"polls/admin.py\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.contrib</span> <span class=\"kn\">import</span> admin\n\n<span class=\"kn\">from</span> <span class=\"nn\">.models</span> <span class=\"kn\">import</span> Choice<span class=\"p\">,</span> Question\n<span class=\"c1\"># ...</span>\nadmin<span class=\"o\">.</span>site<span class=\"o\">.</span>register<span class=\"p\">(</span>Choice<span class=\"p\">)</span>\n</code></pre></figure>\n<p>Now “Choices” is an available option in the Django admin. The “Add choice” form\nlooks like this:</p>\n<img alt=\"Choice admin page\" src=\"/en/1.8/_images/admin10.png\" />\n<p>In that form, the “Question” field is a select box containing every question in the\ndatabase. Django knows that a <a class=\"reference internal\" href=\"/en/1.8/ref/models/fields/#django.db.models.ForeignKey\" title=\"django.db.models.ForeignKey\"><code class=\"xref py py-class docutils literal notranslate\">ForeignKey</code></a> should be\nrepresented in the admin as a <code class=\"docutils literal notranslate\">&lt;select&gt;</code> box. In our case, only one question\nexists at this point.</p>\n<p>Also note the “Add Another” link next to “Question.” Every object with a\n<code class=\"docutils literal notranslate\">ForeignKey</code> relationship to another gets this for free. When you click “Add\nAnother,” you’ll get a popup window with the “Add question” form. If you add a question\nin that window and click “Save,” Django will save the question to the database and\ndynamically add it as the selected choice on the “Add choice” form you’re\nlooking at.</p>\n<p>But, really, this is an inefficient way of adding <code class=\"docutils literal notranslate\">Choice</code> objects to the system.\nIt’d be better if you could add a bunch of Choices directly when you create the\n<code class=\"docutils literal notranslate\">Question</code> object. Let’s make that happen.</p>\n<p>Remove the <code class=\"docutils literal notranslate\">register()</code> call for the <code class=\"docutils literal notranslate\">Choice</code> model. Then, edit the <code class=\"docutils literal notranslate\">Question</code>\nregistration code to read:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"default\"><figcaption class=\"code-block-caption\"><code>polls/admin.py</code></figcaption><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"polls/admin.py\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.contrib</span> <span class=\"kn\">import</span> admin\n\n<span class=\"kn\">from</span> <span class=\"nn\">.models</span> <span class=\"kn\">import</span> Choice<span class=\"p\">,</span> Question\n\n\n<span class=\"k\">class</span> <span class=\"nc\">ChoiceInline</span><span class=\"p\">(</span>admin<span class=\"o\">.</span>StackedInline<span class=\"p\">):</span>\n    model <span class=\"o\">=</span> Choice\n    extra <span class=\"o\">=</span> <span class=\"mi\">3</span>\n\n\n<span class=\"k\">class</span> <span class=\"nc\">QuestionAdmin</span><span class=\"p\">(</span>admin<span class=\"o\">.</span>ModelAdmin<span class=\"p\">):</span>\n    fieldsets <span class=\"o\">=</span> <span class=\"p\">[</span>\n        <span class=\"p\">(</span><span class=\"kc\">None</span><span class=\"p\">,</span>               <span class=\"p\">{</span><span class=\"s1\">&#39;fields&#39;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s1\">&#39;question_text&#39;</span><span class=\"p\">]}),</span>\n        <span class=\"p\">(</span><span class=\"s1\">&#39;Date information&#39;</span><span class=\"p\">,</span> <span class=\"p\">{</span><span class=\"s1\">&#39;fields&#39;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s1\">&#39;pub_date&#39;</span><span class=\"p\">],</span> <span class=\"s1\">&#39;classes&#39;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s1\">&#39;collapse&#39;</span><span class=\"p\">]}),</span>\n    <span class=\"p\">]</span>\n    inlines <span class=\"o\">=</span> <span class=\"p\">[</span>ChoiceInline<span class=\"p\">]</span>\n\nadmin<span class=\"o\">.</span>site<span class=\"o\">.</span>register<span class=\"p\">(</span>Question<span class=\"p\">,</span> QuestionAdmin<span class=\"p\">)</span>\n</code></pre></figure>\n<p>This tells Django: “<code class=\"docutils literal notranslate\">Choice</code> objects are edited on the <code class=\"docutils literal notranslate\">Question</code> admin page. By\ndefault, provide enough fields for 3 choices.”</p>\n<p>Load the “Add question” page to see how that looks:</p>\n<img alt=\"Add question page now has choices on it\" src=\"/en/1.8/_images/admin11t.png\" />\n<p>It works like this: There are three slots for related Choices – as specified\nby <code class=\"docutils literal notranslate\">extra</code> – and each time you come back to the “Change” page for an\nalready-created object, you get another three extra slots.</p>\n<p>At the end of the three current slots you will find an “Add another Choice”\nlink.  If you click on it, a new slot will be added. If you want to remove the\nadded slot, you can click on the X to the top right of the added slot. Note\nthat you can’t remove the original three slots. This image shows an added slot:</p>\n<img alt=\"Additional slot added dynamically\" src=\"/en/1.8/_images/admin15t.png\" />\n<p>One small problem, though. It takes a lot of screen space to display all the\nfields for entering related <code class=\"docutils literal notranslate\">Choice</code> objects. For that reason, Django offers a\ntabular way of displaying inline related objects; you just need to change\nthe <code class=\"docutils literal notranslate\">ChoiceInline</code> declaration to read:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"default\"><figcaption class=\"code-block-caption\"><code>polls/admin.py</code></figcaption><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"polls/admin.py\"><code><span class=\"k\">class</span> <span class=\"nc\">ChoiceInline</span><span class=\"p\">(</span>admin<span class=\"o\">.</span>TabularInline<span class=\"p\">):</span>\n    <span class=\"c1\">#...</span>\n</code></pre></figure>\n<p>With that <code class=\"docutils literal notranslate\">TabularInline</code> (instead of <code class=\"docutils literal notranslate\">StackedInline</code>), the\nrelated objects are displayed in a more compact, table-based format:</p>\n<img alt=\"Add question page now has more compact choices\" src=\"/en/1.8/_images/admin12t.png\" />\n<p>Note that there is an extra “Delete?” column that allows removing rows added\nusing the “Add Another Choice” button and rows that have already been saved.</p>\n</section>\n<section id=\"customize-the-admin-change-list\">\n<h2>Customize the admin change list<a class=\"heading-anchor\" href=\"#customize-the-admin-change-list\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Now that the Question admin page is looking good, let’s make some tweaks to the\n“change list” page – the one that displays all the questions in the system.</p>\n<p>Here’s what it looks like at this point:</p>\n<img alt=\"Polls change list page\" src=\"/en/1.8/_images/admin04t.png\" />\n<p>By default, Django displays the <code class=\"docutils literal notranslate\">str()</code> of each object. But sometimes it’d be\nmore helpful if we could display individual fields. To do that, use the\n<a class=\"reference internal\" href=\"/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display\" title=\"django.contrib.admin.ModelAdmin.list_display\"><code class=\"xref py py-attr docutils literal notranslate\">list_display</code></a> admin option, which is a\ntuple of field names to display, as columns, on the change list page for the\nobject:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"default\"><figcaption class=\"code-block-caption\"><code>polls/admin.py</code></figcaption><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"polls/admin.py\"><code><span class=\"k\">class</span> <span class=\"nc\">QuestionAdmin</span><span class=\"p\">(</span>admin<span class=\"o\">.</span>ModelAdmin<span class=\"p\">):</span>\n    <span class=\"c1\"># ...</span>\n    list_display <span class=\"o\">=</span> <span class=\"p\">(</span><span class=\"s1\">&#39;question_text&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;pub_date&#39;</span><span class=\"p\">)</span>\n</code></pre></figure>\n<p>Just for good measure, let’s also include the <code class=\"docutils literal notranslate\">was_published_recently</code> custom\nmethod from Tutorial 1:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"default\"><figcaption class=\"code-block-caption\"><code>polls/admin.py</code></figcaption><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"polls/admin.py\"><code><span class=\"k\">class</span> <span class=\"nc\">QuestionAdmin</span><span class=\"p\">(</span>admin<span class=\"o\">.</span>ModelAdmin<span class=\"p\">):</span>\n    <span class=\"c1\"># ...</span>\n    list_display <span class=\"o\">=</span> <span class=\"p\">(</span><span class=\"s1\">&#39;question_text&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;pub_date&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;was_published_recently&#39;</span><span class=\"p\">)</span>\n</code></pre></figure>\n<p>Now the question change list page looks like this:</p>\n<img alt=\"Polls change list page, updated\" src=\"/en/1.8/_images/admin13t.png\" />\n<p>You can click on the column headers to sort by those values – except in the\ncase of the <code class=\"docutils literal notranslate\">was_published_recently</code> header, because sorting by the output\nof an arbitrary method is not supported. Also note that the column header for\n<code class=\"docutils literal notranslate\">was_published_recently</code> is, by default, the name of the method (with\nunderscores replaced with spaces), and that each line contains the string\nrepresentation of the output.</p>\n<p>You can improve that by giving that method (in <code class=\"file docutils literal notranslate\">polls/models.py</code>) a few\nattributes, as follows:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"default\"><figcaption class=\"code-block-caption\"><code>polls/models.py</code></figcaption><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"polls/models.py\"><code><span class=\"k\">class</span> <span class=\"nc\">Question</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    <span class=\"c1\"># ...</span>\n    <span class=\"k\">def</span> <span class=\"nf\">was_published_recently</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        <span class=\"k\">return</span> <span class=\"bp\">self</span><span class=\"o\">.</span>pub_date <span class=\"o\">&gt;=</span> timezone<span class=\"o\">.</span>now<span class=\"p\">()</span> <span class=\"o\">-</span> datetime<span class=\"o\">.</span>timedelta<span class=\"p\">(</span>days<span class=\"o\">=</span><span class=\"mi\">1</span><span class=\"p\">)</span>\n    was_published_recently<span class=\"o\">.</span>admin_order_field <span class=\"o\">=</span> <span class=\"s1\">&#39;pub_date&#39;</span>\n    was_published_recently<span class=\"o\">.</span>boolean <span class=\"o\">=</span> <span class=\"kc\">True</span>\n    was_published_recently<span class=\"o\">.</span>short_description <span class=\"o\">=</span> <span class=\"s1\">&#39;Published recently?&#39;</span>\n</code></pre></figure>\n<p>For more information on these method properties, see\n<a class=\"reference internal\" href=\"/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display\" title=\"django.contrib.admin.ModelAdmin.list_display\"><code class=\"xref py py-attr docutils literal notranslate\">list_display</code></a>.</p>\n<p>Edit your <code class=\"file docutils literal notranslate\">polls/admin.py</code> file again and add an improvement to the\n<code class=\"docutils literal notranslate\">Question</code> change list page: filters using the\n<a class=\"reference internal\" href=\"/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter\" title=\"django.contrib.admin.ModelAdmin.list_filter\"><code class=\"xref py py-attr docutils literal notranslate\">list_filter</code></a>. Add the following line to\n<code class=\"docutils literal notranslate\">QuestionAdmin</code>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>list_filter <span class=\"o\">=</span> <span class=\"p\">[</span><span class=\"s1\">&#39;pub_date&#39;</span><span class=\"p\">]</span>\n</code></pre></div>\n<p>That adds a “Filter” sidebar that lets people filter the change list by the\n<code class=\"docutils literal notranslate\">pub_date</code> field:</p>\n<img alt=\"Polls change list page, updated\" src=\"/en/1.8/_images/admin14t.png\" />\n<p>The type of filter displayed depends on the type of field you’re filtering on.\nBecause <code class=\"docutils literal notranslate\">pub_date</code> is a <a class=\"reference internal\" href=\"/en/1.8/ref/models/fields/#django.db.models.DateTimeField\" title=\"django.db.models.DateTimeField\"><code class=\"xref py py-class docutils literal notranslate\">DateTimeField</code></a>, Django\nknows to give appropriate filter options: “Any date,” “Today,” “Past 7 days,”\n“This month,” “This year.”</p>\n<p>This is shaping up well. Let’s add some search capability:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>search_fields <span class=\"o\">=</span> <span class=\"p\">[</span><span class=\"s1\">&#39;question_text&#39;</span><span class=\"p\">]</span>\n</code></pre></div>\n<p>That adds a search box at the top of the change list. When somebody enters\nsearch terms, Django will search the <code class=\"docutils literal notranslate\">question_text</code> field. You can use as many\nfields as you’d like – although because it uses a <code class=\"docutils literal notranslate\">LIKE</code> query behind the\nscenes, limiting the number of search fields to a reasonable number will make\nit easier for your database to do the search.</p>\n<p>Now’s also a good time to note that change lists give you free pagination. The\ndefault is to display 100 items per page. <a class=\"reference internal\" href=\"/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_per_page\" title=\"django.contrib.admin.ModelAdmin.list_per_page\"><code class=\"xref py py-attr docutils literal notranslate\">Change list pagination</code></a>, <a class=\"reference internal\" href=\"/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.search_fields\" title=\"django.contrib.admin.ModelAdmin.search_fields\"><code class=\"xref py py-attr docutils literal notranslate\">search boxes</code></a>, <a class=\"reference internal\" href=\"/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter\" title=\"django.contrib.admin.ModelAdmin.list_filter\"><code class=\"xref py py-attr docutils literal notranslate\">filters</code></a>, <a class=\"reference internal\" href=\"/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.date_hierarchy\" title=\"django.contrib.admin.ModelAdmin.date_hierarchy\"><code class=\"xref py py-attr docutils literal notranslate\">date-hierarchies</code></a>, and\n<a class=\"reference internal\" href=\"/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display\" title=\"django.contrib.admin.ModelAdmin.list_display\"><code class=\"xref py py-attr docutils literal notranslate\">column-header-ordering</code></a>\nall work together like you think they should.</p>\n</section>\n<section id=\"customize-the-admin-look-and-feel\">\n<h2>Customize the admin look and feel<a class=\"heading-anchor\" href=\"#customize-the-admin-look-and-feel\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Clearly, having “Django administration” at the top of each admin page is\nridiculous. It’s just placeholder text.</p>\n<p>That’s easy to change, though, using Django’s template system. The Django admin\nis powered by Django itself, and its interfaces use Django’s own template\nsystem.</p>\n<section id=\"customizing-your-project-s-templates\">\n<span id=\"ref-customizing-your-projects-templates\"></span><h3>Customizing your <em>project’s</em> templates<a class=\"heading-anchor\" href=\"#customizing-your-project-s-templates\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Create a <code class=\"docutils literal notranslate\">templates</code> directory in your project directory (the one that\ncontains <code class=\"docutils literal notranslate\">manage.py</code>). Templates can live anywhere on your filesystem that\nDjango can access. (Django runs as whatever user your server runs.) However,\nkeeping your templates within the project is a good convention to follow.</p>\n<p>Open your settings file (<code class=\"file docutils literal notranslate\">mysite/settings.py</code>, remember) and add a\n<a class=\"reference internal\" href=\"/en/1.8/ref/settings/#std-setting-TEMPLATES-DIRS\"><code class=\"xref std std-setting docutils literal notranslate\">DIRS</code></a> option in the <a class=\"reference internal\" href=\"/en/1.8/ref/settings/#std-setting-TEMPLATES\"><code class=\"xref std std-setting docutils literal notranslate\">TEMPLATES</code></a> setting:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"default\"><figcaption class=\"code-block-caption\"><code>mysite/settings.py</code></figcaption><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"mysite/settings.py\"><code>TEMPLATES <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"p\">{</span>\n        <span class=\"s1\">&#39;BACKEND&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;django.template.backends.django.DjangoTemplates&#39;</span><span class=\"p\">,</span>\n        <span class=\"s1\">&#39;DIRS&#39;</span><span class=\"p\">:</span> <span class=\"p\">[</span>os<span class=\"o\">.</span>path<span class=\"o\">.</span>join<span class=\"p\">(</span>BASE_DIR<span class=\"p\">,</span> <span class=\"s1\">&#39;templates&#39;</span><span class=\"p\">)],</span>\n        <span class=\"s1\">&#39;APP_DIRS&#39;</span><span class=\"p\">:</span> <span class=\"kc\">True</span><span class=\"p\">,</span>\n        <span class=\"s1\">&#39;OPTIONS&#39;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s1\">&#39;context_processors&#39;</span><span class=\"p\">:</span> <span class=\"p\">[</span>\n                <span class=\"s1\">&#39;django.template.context_processors.debug&#39;</span><span class=\"p\">,</span>\n                <span class=\"s1\">&#39;django.template.context_processors.request&#39;</span><span class=\"p\">,</span>\n                <span class=\"s1\">&#39;django.contrib.auth.context_processors.auth&#39;</span><span class=\"p\">,</span>\n                <span class=\"s1\">&#39;django.contrib.messages.context_processors.messages&#39;</span><span class=\"p\">,</span>\n            <span class=\"p\">],</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">]</span>\n</code></pre></figure>\n<p><a class=\"reference internal\" href=\"/en/1.8/ref/settings/#std-setting-TEMPLATES-DIRS\"><code class=\"xref std std-setting docutils literal notranslate\">DIRS</code></a> is a list of filesystem directories to check\nwhen loading Django templates; it’s a search path.</p>\n<p>Now create a directory called <code class=\"docutils literal notranslate\">admin</code> inside <code class=\"docutils literal notranslate\">templates</code>, and copy the\ntemplate <code class=\"docutils literal notranslate\">admin/base_site.html</code> from within the default Django admin\ntemplate directory in the source code of Django itself\n(<code class=\"docutils literal notranslate\">django/contrib/admin/templates</code>) into that directory.</p>\n<aside class=\"admonition-where-are-the-django-source-files admonition\" role=\"note\">\n<p class=\"admonition-title\">Where are the Django source files?</p>\n<p>If you have difficulty finding where the Django source files are located\non your system, run the following command:</p>\n<div class=\"code-block\" data-language=\"console\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code><span class=\"gp\">$ </span>python -c <span class=\"s2\">&quot;</span>\n<span class=\"go\">import sys</span>\n<span class=\"go\">sys.path = sys.path[1:]</span>\n<span class=\"go\">import django</span>\n<span class=\"go\">print(django.__path__)&quot;</span>\n</code></pre></div>\n</aside>\n<p>Then, just edit the file and replace\n<code class=\"docutils literal notranslate\">{{ site_header|default:_('Django administration') }}</code> (including the curly\nbraces) with your own site’s name as you see fit. You should end up with\na section of code like:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"cp\">{%</span> <span class=\"k\">block</span> <span class=\"nv\">branding</span> <span class=\"cp\">%}</span>\n<span class=\"p\">&lt;</span><span class=\"nt\">h1</span> <span class=\"na\">id</span><span class=\"o\">=</span><span class=\"s\">&quot;site-name&quot;</span><span class=\"p\">&gt;&lt;</span><span class=\"nt\">a</span> <span class=\"na\">href</span><span class=\"o\">=</span><span class=\"s\">&quot;</span><span class=\"cp\">{%</span> <span class=\"k\">url</span> <span class=\"s1\">&#39;admin:index&#39;</span> <span class=\"cp\">%}</span><span class=\"s\">&quot;</span><span class=\"p\">&gt;</span>Polls Administration<span class=\"p\">&lt;/</span><span class=\"nt\">a</span><span class=\"p\">&gt;&lt;/</span><span class=\"nt\">h1</span><span class=\"p\">&gt;</span>\n<span class=\"cp\">{%</span> <span class=\"k\">endblock</span> <span class=\"cp\">%}</span>\n</code></pre></div>\n<p>We use this approach to teach you how to override templates. In an actual\nproject, you would probably use\nthe <a class=\"reference internal\" href=\"/en/1.8/ref/contrib/admin/#django.contrib.admin.AdminSite.site_header\" title=\"django.contrib.admin.AdminSite.site_header\"><code class=\"xref py py-attr docutils literal notranslate\">django.contrib.admin.AdminSite.site_header</code></a> attribute to more easily\nmake this particular customization.</p>\n<p>This template file contains lots of text like <code class=\"docutils literal notranslate\">{% block branding %}</code>\nand <code class=\"docutils literal notranslate\">{{ title }}</code>. The <code class=\"docutils literal notranslate\">{%</code> and <code class=\"docutils literal notranslate\">{{</code> tags are part of Django’s\ntemplate language. When Django renders <code class=\"docutils literal notranslate\">admin/base_site.html</code>, this\ntemplate language will be evaluated to produce the final HTML page.\nDon’t worry if you can’t make any sense of the template right now –\nwe’ll delve into Django’s templating language in Tutorial 3.</p>\n<p>Note that any of Django’s default admin templates can be overridden. To\noverride a template, just do the same thing you did with <code class=\"docutils literal notranslate\">base_site.html</code> –\ncopy it from the default directory into your custom directory, and make\nchanges.</p>\n</section>\n<section id=\"customizing-your-application-s-templates\">\n<h3>Customizing your <em>application’s</em> templates<a class=\"heading-anchor\" href=\"#customizing-your-application-s-templates\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Astute readers will ask: But if <a class=\"reference internal\" href=\"/en/1.8/ref/settings/#std-setting-TEMPLATES-DIRS\"><code class=\"xref std std-setting docutils literal notranslate\">DIRS</code></a> was empty by\ndefault, how was Django finding the default admin templates? The answer is\nthat, since <a class=\"reference internal\" href=\"/en/1.8/ref/settings/#std-setting-TEMPLATES-APP_DIRS\"><code class=\"xref std std-setting docutils literal notranslate\">APP_DIRS</code></a> is set to <code class=\"docutils literal notranslate\">True</code>,\nDjango automatically looks for a <code class=\"docutils literal notranslate\">templates/</code> subdirectory within each\napplication package, for use as a fallback (don’t forget that\n<code class=\"docutils literal notranslate\">django.contrib.admin</code> is an application).</p>\n<p>Our poll application is not very complex and doesn’t need custom admin\ntemplates. But if it grew more sophisticated and required modification of\nDjango’s standard admin templates for some of its functionality, it would be\nmore sensible to modify the <em>application’s</em> templates, rather than those in the\n<em>project</em>. That way, you could include the polls application in any new project\nand be assured that it would find the custom templates it needed.</p>\n<p>See the <a class=\"reference internal\" href=\"/en/1.8/topics/templates/#template-loading\"><span class=\"std std-ref\">template loading documentation</span></a> for more\ninformation about how Django finds its templates.</p>\n</section>\n</section>\n<section id=\"customize-the-admin-index-page\">\n<h2>Customize the admin index page<a class=\"heading-anchor\" href=\"#customize-the-admin-index-page\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>On a similar note, you might want to customize the look and feel of the Django\nadmin index page.</p>\n<p>By default, it displays all the apps in <a class=\"reference internal\" href=\"/en/1.8/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\">INSTALLED_APPS</code></a> that have been\nregistered with the admin application, in alphabetical order. You may want to\nmake significant changes to the layout. After all, the index is probably the\nmost important page of the admin, and it should be easy to use.</p>\n<p>The template to customize is <code class=\"docutils literal notranslate\">admin/index.html</code>. (Do the same as with\n<code class=\"docutils literal notranslate\">admin/base_site.html</code> in the previous section – copy it from the default\ndirectory to your custom template directory.) Edit the file, and you’ll see it\nuses a template variable called <code class=\"docutils literal notranslate\">app_list</code>. That variable contains every\ninstalled Django app. Instead of using that, you can hard-code links to\nobject-specific admin pages in whatever way you think is best. Again,\ndon’t worry if you can’t understand the template language – we’ll cover that\nin more detail in Tutorial 3.</p>\n<p>When you’re comfortable with the admin site, read <a class=\"reference internal\" href=\"/en/1.8/intro/tutorial03/\"><span class=\"doc\">part 3 of this tutorial</span></a> to start working on public poll views.</p>\n</section>","rootId":"writing-your-first-django-app-part-2","toc":[{"title":"Creating an admin user","anchor":"creating-an-admin-user","children":[]},{"title":"Start the development server","anchor":"start-the-development-server","children":[]},{"title":"Enter the admin site","anchor":"enter-the-admin-site","children":[]},{"title":"Make the poll app modifiable in the admin","anchor":"make-the-poll-app-modifiable-in-the-admin","children":[]},{"title":"Explore the free admin functionality","anchor":"explore-the-free-admin-functionality","children":[]},{"title":"Customize the admin form","anchor":"customize-the-admin-form","children":[]},{"title":"Adding related objects","anchor":"adding-related-objects","children":[]},{"title":"Customize the admin change list","anchor":"customize-the-admin-change-list","children":[]},{"title":"Customize the admin look and feel","anchor":"customize-the-admin-look-and-feel","children":[{"title":"Customizing your project’s templates","anchor":"customizing-your-project-s-templates","children":[]},{"title":"Customizing your application’s templates","anchor":"customizing-your-application-s-templates","children":[]}]},{"title":"Customize the admin index page","anchor":"customize-the-admin-index-page","children":[]}],"breadcrumbs":[{"docname":"intro/index","title":"Getting started","url":"/en/1.8/intro/"}],"prev":{"docname":"intro/tutorial01","title":"Writing your first Django app, part 1","url":"/en/1.8/intro/tutorial01/"},"next":{"docname":"intro/tutorial03","title":"Writing your first Django app, part 3","url":"/en/1.8/intro/tutorial03/"},"formats":{"html":"/en/1.8/intro/tutorial02/","markdown":"/en/1.8/intro/tutorial02.md","json":"/en/1.8/intro/tutorial02.json"},"source":"https://github.com/django/django/blob/stable/1.8.x/docs/intro/tutorial02.txt","official":"https://docs.djangoproject.com/en/1.8/intro/tutorial02/","inVersions":["dev","6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11","1.10","1.9","1.8"],"inLocales":["en"]}