Code


Version 1 (modified by spike, 7 years ago) (diff)

--

=====================================
>>!
Writing your first Django app, part 2
<<!
>>!!
두번째: 자동으로 만들어지는 관리 사이트(admin site) 둘러보기
<<!!
=====================================

>>!
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.
<<!
>>!!
이 페이지는
`첫번째: 처음 실행하기, 모델(model) 만들기, 데이터베이스 API`_의 그
다음 부분을 설명합니다.
<<!!

>>!
.. _Tutorial 1: ../tutorial01/
<<!
>>!!
.. _첫번째: 처음 실행하기, 모델(model) 만들기, 데이터베이스 API: ../tutorial01/
<<!!

>>!
.. admonition:: Philosophy

    Generating admin sites for your staff or clients to add, change and delete
    content is tedious work that doesn't require much creativity. For that reason,
    Django entirely automates creation of admin interfaces for models.

    Django was written in a newsroom environment, with a very clear separation
    between "content publishers" and the "public" site. Site managers use the
    system to add news stories, events, sports scores, etc., and that content is
    displayed on the public site. Django solves the problem of creating a unified
    interface for site administrators to edit content.

    The admin isn't necessarily intended to be used by site visitors; it's for site
    managers.
<<!
>>!!
.. admonition:: 개념
    기본적으로 장고 관리 사이트는 콘텐츠를 더하고, 바꾸고, 지우는
    역할을 합니다. 이 관리 사이트는 모델(model)을 따르기 때문에 만드는
    건 단순합니다.

    장고는 뉴스 편집 환경에서 작성되어서 콘텐츠를 만드는 것과 배포하는
    것이 분리되어 있습니다. 사이트 관리자는 새로운 뉴스나 경기 기록
    같은 것을 추가하는 시스템을 사용하고 작성된 콘텐츠는 공개 사이트에
    올려집니다. 장고는 콘텐츠를 편집하는 사이트 관리자를 위해서 일관된
    인터페이스를 제공합니다.

<<!!

>>!
Activate the admin site
<<!
>>!!
관리 사이트 시작하기
<<!!
=======================

>>!
The Django admin site is not activated by default -- it's an opt-in thing. To
activate the admin site for your installation, do these three things:
<<!
>>!!
장고 관리 사이트는 기본으로 실행되지 않습니다. -- 선택사항입니다.
장고를 설치할 때 관리 사이트를 시작하려면, 세가지 작업이 필요합니다.:
<<!!

>>!
    * Add ``"django.contrib.admin"`` to your ``INSTALLED_APPS`` setting.
    * Run ``python manage.py syncdb``. Since you have added a new application
      to ``INSTALLED_APPS``, the database tables need to be updated.
    * Edit your ``mysite/urls.py`` file and uncomment the line below
      "Uncomment this for admin:". This file is a URLconf; we'll dig into
      URLconfs in the next tutorial. For now, all you need to know is that it
      maps URL roots to applications.
<<!
>>!!
    * ``INSTALLED_APPS`` 설정에서 ``"django.contrib.admin"``를
      추가하세요.
    * ``python manage.py syncdb``를 실행합니다. 장고에서는
      ``INSTALLED_APPS``에 추가된 새로운 어플리케이션이 있고
      데이터베이스 테이블을 업데이트해야한다면 이 명령을 실행합니다.
    * ``mysite/urls.py``에서 "Uncomment this for admin:" 아래 줄의
      주석을 제거하세요. 이 파일이 ``URLconfs``입니다.; ``URLconfs``에
      대해서는 다음 페이지에서 설명합니다. 간단하게 설명하자면 관리
      사이트 url을 추가하는 것입니다.
<<!!

>>!
Start the development server
<<!
>>!!
개발 서버 시작하기
<<!!
============================

>>!
Let's start the development server and explore the admin site.

Recall from Tutorial 1 that you start the development server like so::
<<!
>>!!
이전 페이지에서 설명한 개발서버를 시작하는 방법입니다::
<<!!

    python manage.py runserver

>>!
Now, open a Web browser and go to "/admin/" on your local domain -- e.g.,
http://127.0.0.1:8000/admin/. You should see the admin's login screen:
<<!
>>!!
웹 브라우저에서 로컬 도메인에서 "/admin/"을 엽니다. -- 설정을 바꾸지
않았다면 http://127.0.0.1:8000/admin/ 에서 관리 사이트를 확인할 수
있습니다.
<<!!

>>!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin01.png
   :alt: Django admin login screen
<<!
>>!!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin01.png
   :alt: 장고 관리 사이트 로그인 페이지
<<!!

>>!
Enter the admin site
<<!
>>!!
관리 사이트에 들어가기
<<!!
====================

>>!
Now, try logging in. (You created a superuser account in the first part of this
tutorial, remember?) You should see the Django admin index page:
<<!
>>!!
로그인합니다. (이전 페이지에서 설명한 관리자 계정을 만들었죠?) 장고
관리 사이트의 첫 페이지입니다.:
<<!!

>>!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin02t.png
   :alt: Django admin index page
   :target: http://media.djangoproject.com/img/doc/tutorial/admin02.png
<<!
>>!!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin02t.png
   :alt: 장고 관리 사이트 기본 페이지
   :target: http://media.djangoproject.com/img/doc/tutorial/admin02.png
<<!!

>>!
You should see a few other types of editable content, including groups, users
and sites. These are core features Django ships with by default.
<<!
>>!!
그룹, 사용자, 사이트 등 관리할 수 있는 몇가지 항목을 볼 수 있습니다.
이 항목들은 장고의 핵심 기능들입니다.
<<!!

>>!
.. _"I can't log in" questions: ../faq/#the-admin-site
<<!
>>!!
.. _"질문: 로그인할 수 없어요.": ../faq/#the-admin-site
<<!!

>>!
Make the poll app modifiable in the admin
<<!
>>!!
관리 사이트에서 관리할 수 있도로 ㄱpoll 어플리케이션을 바꿔봅니다.
<<!!
=========================================

>>!
But where's our poll app? It's not displayed on the admin index page.

Just one thing to do: We need to specify in the ``Poll`` model that ``Poll``
objects have an admin interface. Edit the ``mysite/polls/models.py`` file and
make the following change to add an inner ``Admin`` class::
<<!
>>!!
이전 페이지에서 만들었던 poll 어플리케이션이 보이질 않습니다. 아직
관리 사이트에서 보이지 않는 것이 당연합니다.

한가지를 더해야 합니다.: ``Poll`` 모델이 관리 인터페이스를 갇도록
지정해야 하는데요, ``mysite/polls/models.py``을 열어서 다음과 같이
``Admin`` class에 추가합니다.::
<<!!

    class Poll(models.Model):
        # ...
        class Admin:
            pass

>>!
The ``class Admin`` will contain all the settings that control how this model
appears in the Django admin.  All the settings are optional, however, so
creating an empty class means "give this object an admin interface using
all the default options."

Now reload the Django admin page to see your changes. Note that you don't have
to restart the development server -- the server will auto-reload your project,
so any modifications code will be seen immediately in your browser.
<<!
>>!!
``class Admin``은 이 모델(model)이 관리 사이트에서 어떻게 표현될지를
설정합니다. 모든 설정은 선택사항이라서 기본 설정을 가진 빈 클래스를
만들어도 됩니다.
<<!!

>>!
Explore the free admin functionality
<<!
>>!!
관리 기능 사용해보기
<<!!
====================================

>>!
Now that ``Poll`` has the inner ``Admin`` class, Django knows that it should be
displayed on the admin index page:
<<!
>>!!
이제 ``Poll``은 ``Admin``을 포함하고 있고 관리 사이트에서 나타납니다.
<<!!

>>!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin03t.png
   :alt: Django admin index page, now with polls displayed
   :target: http://media.djangoproject.com/img/doc/tutorial/admin03.png
<<!
>>!!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin03t.png
   :alt: 장고 관리 사이트 첫 페이지에서 polls이 나타납니다.
   :target: http://media.djangoproject.com/img/doc/tutorial/admin03.png
<<!!

>>!
Click "Polls." Now you're at the "change list" page for polls. This page
displays all the polls in the database and lets you choose one to change it.
There's the "What's up?" poll we created in the first tutorial:
<<!
>>!!
"Polls"를 눌러서 "change list" 페이지에 들어갑니다. 이 페이지는
데이터베이스에 있는 모든 poll을 보여주고 각각 바꿀 수 있도록 합니다.
이전 페이지에서 만들었던 "What's up?" poll이 있군요.
<<!!

>>!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin04t.png
   :alt: Polls change list page
   :target: http://media.djangoproject.com/img/doc/tutorial/admin04.png
<<!
>>!!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin04t.png
   :alt: Polls의 "change list" 페이지
   :target: http://media.djangoproject.com/img/doc/tutorial/admin04.png
<<!!

>>!
Click the "What's up?" poll to edit it:
<<!
>>!!
"What's up?" poll을 눌러서 편집합니다.:
<<!!

>>!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin05t.png
   :alt: Editing form for poll object
   :target: http://media.djangoproject.com/img/doc/tutorial/admin05.png
<<!
>>!!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin05t.png
   :alt: poll 객체를 편집합니다.
   :target: http://media.djangoproject.com/img/doc/tutorial/admin05.png
<<!!

>>!
Things to note here:
<<!
>>!!
참고할 사항들:
<<!!

>>!
    * The form is automatically generated from the Poll model.
    * The different model field types (``models.DateTimeField``,
      ``models.CharField``) correspond to the appropriate HTML input
      widget. Each type of field knows how to display itself in the
      Django admin.
    * Each ``DateTimeField`` gets free JavaScript shortcuts. Dates get
     a "Today" shortcut and calendar popup, and times get a "Now"
     shortcut and a convenient popup that lists commonly entered
     times.
<<!
>>!!
    * 이 폼은 Poll 모델이 자동으로 만들어줍니다.
    * ``models.DateTimeField``, ``models.CharField`` 같이 각각의
      필드(Field)들은 HTML에서 서로 다른 위젯으로 표현됩니다.
<<!!

>>!
The bottom part of the page gives you a couple of options:
<<!
>>!!
페이지 아래에 몇가지 선택버튼이 있습니다.
<<!!

>>!
    * Save -- Saves changes and returns to the change-list page for
      this type of object.
    * Save and continue editing -- Saves changes and reloads the admin
      page for this object.
    * Save and add another -- Saves changes and loads a new, blank
      form for this type of object.
    * Delete -- Displays a delete confirmation page.
<<!
>>!!
    * Save -- 변경사항을 저장하고 "change list"로 돌아갑니다.
    * Save and continue editing -- 변경사항을 저장하고 이 페이지를
      다시 표시합니다.
    * Save and add another -- 변경사항을 추가하고 새로 객체를 추가할
      수 있도록 빈 폼을 표시합니다.
    * Delete -- 객체를 지웁니다.
<<!!

>>!
Change the "Date published" by clicking the "Today" and "Now" shortcuts. Then
click "Save and continue editing." Then click "History" in the upper right.
You'll see a page listing all changes made to this object via the Django admin,
with the timestamp and username of the person who made the change:
<<!
>>!!
"Today"와 "Now" 링크를 눌러서 "Date published"를 바꿔봅니다. 그리고
"Save and continue editing."을 누릅니다. 그러고 나서 오른쪽 위에 있는
"History"를 누릅니다. 그러면 장고 관리 사이트에서 사용자이름과 시간과
함께 이 객체가 어떻게 변해왔는지를 보여줍니다.
<<!!

>>!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin06t.png
   :alt: History page for poll object
   :target: http://media.djangoproject.com/img/doc/tutorial/admin06.png
<<!
>>!!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin06t.png
   :alt: poll 객체의 변경기록
   :target: http://media.djangoproject.com/img/doc/tutorial/admin06.png
<<!!

>>!
Customize the admin form
<<!
>>!!
관리 사이트의 폼 바꿔보기
<<!!
========================

>>!
Take a few minutes to marvel at all the code you didn't have to write.

Let's customize this a bit. We can reorder the fields by explicitly adding a
``fields`` parameter to ``Admin``::
<<!
>>!!
폼을 좀 바꿔볼까요? ``Admin``에 ``fields`` 항목을 추가해서 표시되는 필드의 순서를 바꿀 수 있습니다.
<<!!

        class Admin:
            fields = (
                (None, {'fields': ('pub_date', 'question')}),
            )

>>!
That made the "Publication date" show up first instead of second:
<<!
>>!!
"Publication date"를 "question" 앞에 보여주도록 합니다.
<<!!

>>!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin07.png
   :alt: Fields have been reordered
<<!
>>!!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin07.png
   :alt: 필드 순서가 바뀌었습니다.
<<!!

>>!
This isn't impressive with only two fields, but for admin forms with dozens
of fields, choosing an intuitive order is an important usability detail.
<<!
>>!!
필드가 두개만 있다면 별 의미가 없지만, 관리 폼에 필드수가 많다면
직관적인 순서로 바꾸는게 훨씬 낫겠죠.
<<!!

>>!
And speaking of forms with dozens of fields, you might want to split the form
up into fieldsets::
<<!
>>!!
필드수를 적절히 나누고 싶다면 필드셋(fieldsets)으로 나눌 수 있습니다.
<<!!

        class Admin:
            fields = (
                (None, {'fields': ('question',)}),
                ('Date information', {'fields': ('pub_date',)}),
            )

>>!
The first element of each tuple in ``fields`` is the title of the fieldset.
Here's what our form looks like now:
<<!
>>!!
첫번째 튜플(tuple)의 'field' 값은 필드셋(fieldset)의 제목입니다.
아래와 같이 보입니다.:
<<!!

>>!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin08t.png
   :alt: Form has fieldsets now
   :target: http://media.djangoproject.com/img/doc/tutorial/admin08.png
<<!
>>!!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin08t.png
   :alt: 필드셋을 가진 폼
   :target: http://media.djangoproject.com/img/doc/tutorial/admin08.png
<<!!

>>!
You can assign arbitrary HTML classes to each fieldset. Django provides a
``"collapse"`` class that displays a particular fieldset initially collapsed.
This is useful when you have a long form that contains a number of fields that
aren't commonly used::
<<!
>>!!
강제로 각 필드셋(fieldset)에 `HTML class` 값을 부여할 수도 있습니다.
장고에서는 ``"collapse"`` class를 사용해서 필드셋(fieldset)을 기본으로
접어서 표시할 수 있습니다. 이 기능 필드셋이 잘 사용하지 않은 필드를
많이 포함하고 있을 때 유용합니다.::
<<!!

        class Admin:
            fields = (
                (None, {'fields': ('question',)}),
                ('Date information', {'fields': ('pub_date',), 'classes': 'collapse'}),
            )

>>!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin09.png
   :alt: Fieldset is initially collapsed
<<!
>>!!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin09.png
   :alt: 접힌 필드셋
<<!!

>>!
Adding related objects
<<!
>>!!
관계된 객체 추가하기
<<!!
======================

>>!
OK, we have our Poll admin page. But a ``Poll`` has multiple ``Choices``, and
the admin page doesn't display choices.

Yet.

There are two ways to solve this problem. The first is to give the ``Choice``
model its own inner ``Admin`` class, just as we did with ``Poll``. Here's what
that would look like::
<<!
>>!!
자 그럼, Poll 관리 사이트를 갖게 되었습니다. 다만 아직 ``Poll``은 여러
개의 ``Choices``를 가지고 있지만, 관리 사이트에서는 표시되지 않고
있습니다.

이 문제를 해결하려면 두 가지 방법이 있습니다. 한가지는 ``Poll``에서 했던
것처럼 ``Choice`` 모델에도 ``Admin`` class를 추가하는 방법입니다. 예::
<<!!

    class Choice(models.Model):
        # ...
        class Admin:
            pass

>>!
Now "Choices" is an available option in the Django admin. The "Add choice" form
looks like this:
<<!
>>!!
장고 관리 사이트에서 아래와 같은 "Add choice" 폼이 추가되었습니다.:
<<!!

>>!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin10.png
   :alt: Choice admin page
<<!
>>!!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin10.png
   :alt: 관리자페이지에서 Choice
<<!!

>>!
In that form, the "Poll" field is a select box containing every poll in the
database. Django knows that a ``ForeignKey`` should be represented in the admin
as a ``<select>`` box. In our case, only one poll exists at this point.

Also note the "Add Another" link next to "Poll." Every object with a ForeignKey
relationship to another gets this for free. When you click "Add Another," you'll
get a popup window with the "Add poll" form. If you add a poll in that window
and click "Save," Django will save the poll to the database and dynamically add
it as the selected choice on the "Add choice" form you're looking at.

But, really, this is an inefficient way of adding Choice objects to the system.
It'd be better if you could add a bunch of Choices directly when you create the
Poll object. Let's make that happen.
<<!
>>!!
이 폼에서 "Poll" 필드는 선택박스(select box)이고 데이터베이스에 있는
모든 poll을 담고 있습니다. ``ForeignKey``가 관리 사이트에서
``<select>``로 표현되었습니다. 여기서 poll은 하나밖에 없군요.

"Poll" 옆에 "Add Another"처럼 다른 모델 객체와 ForeignKey 관계를 가진
모델 객체는 "Add Another" 버튼을 가지게 됩니다. "Add Another"를 누르게
되면 팝업창으로 "Add poll"폼을 작성하고 "Save"버튼을 누르면 poll을
데이터베이스에 저장합니다.
<<!!

>>!
Remove the ``Admin`` for the Choice model. Then, edit the ``ForeignKey(Poll)``
field like so::
<<!
>>!!
Choice 모델에서 ``Admin``을 지웁니다. 그리고 ``ForeignKey(Poll)``
다음처럼 해줍니다.::
<<!!

    poll = models.ForeignKey(Poll, edit_inline=models.STACKED, num_in_admin=3)

>>!
This tells Django: "Choice objects are edited on the Poll admin page. By
default, provide enough fields for 3 Choices."

Then change the other fields in ``Choice`` to give them ``core=True``::
<<!
>>!!
위 코드는 이런 뜻입니다.: "Choice 객체는 Poll 관리 페이지에서
편집됩니다. 기본으로 3개의 Choices필드를 제공합니다."

그리고 나서 ``Choice``에 있는 다른 필드에 ``core=True``를 추가합니다.::
<<!!

    choice = models.CharField(max_length=200, core=True)
    votes = models.IntegerField(core=True)

>>!
This tells Django: "When you edit a Choice on the Poll admin page, the 'choice'
and 'votes' fields are required. The presence of at least one of them signifies
the addition of a new Choice object, and clearing both of them signifies the
deletion of that existing Choice object."

Load the "Add poll" page to see how that looks:
<<!
>>!!
위 코드는 이런 뜻입니다.: "Poll 관리 페이지에서 Choice를 편집할 때
'choice'"와 'votes' 필드가 반드시 필요합니다. 둘 중 하나라도 있다는
것은 새로운 객체를 추가한다는 것을 뜻하고 두 필드를 지우는 것은 Choice
객체를 지운다는 뜻입니다.
<<!!

>>!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin11t.png
   :alt: Add poll page now has choices on it
   :target: http://media.djangoproject.com/img/doc/tutorial/admin11.png
<<!
>>!!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin11t.png
   :alt: 여러 개의 choice 폼을 가지고 있는 poll 추가 페이지
   :target: http://media.djangoproject.com/img/doc/tutorial/admin11.png
<<!!

>>!
It works like this: There are three slots for related Choices -- as specified
by ``num_in_admin`` -- but each time you come back to the "Change" page for an
already-created object, you get one extra slot. (This means there's no
hard-coded limit on how many related objects can be added.) If you wanted space
for three extra Choices each time you changed the poll, you'd use
``num_extra_on_change=3``.
<<!
>>!!
이렇게 움직입니다.: Poll과 연결된 Choices에 3개의 슬롯(slots)이
있습니다. -- ``num_in_admin``으로 지정했었죠?! - 하지만 이미
만들어놓은 객체를 바꾸기 위해서 "Change" 페이지를 볼때마다 slot이
하나씩 추가됩니다. (즉, 3개로 지정했다고 해서 "Choices"가 3개만
나온다는 게 아닙니다.) 이게 아니라 항상 poll을 바꿀 때마다 3개씩
Choice 필드를 보여주려고 한다면 위에서처럼
``num_extra_on_change=3``라고 지정하세요.
<<!!

>>!
One small problem, though. It takes a lot of screen space to display all the
fields for entering related Choice objects. For that reason, Django offers an
alternate way of displaying inline related objects::
<<!
>>!!
하지만 작은 문제가 있습니다. 모든 필드를 한 화면에 표시해서 페이지
아래로 넘거가기 때문에 한줄에 관련 객체(related object)를
표시할 수도 있습니다.
<<!!

    poll = models.ForeignKey(Poll, edit_inline=models.TABULAR, num_in_admin=3)

>>!
With that ``edit_inline=models.TABULAR`` (instead of ``models.STACKED``), the
related objects are displayed in a more compact, table-based format:
<<!
>>!!
``edit_inline=models.TABULAR`` (``models.STACKED`` 대신에)으로
표현하면 관련 객체들이 테이블 모영으로 좀더 모아져서 보여집니다.:
<<!!

>>!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin12.png
   :alt: Add poll page now has more compact choices
<<!
>>!!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin12.png
   :alt: poll을 추가하는 페이지에 choices를 간략하게 표시됩니다.
<<!!

>>!
Customize the admin change list
<<!
>>!!
바꾸기 목록을 바꿔보기
<<!!
===============================

>>!
Now that the Poll admin page is looking good, let's make some tweaks to the
"change list" page -- the one that displays all the polls in the system.

Here's what it looks like at this point:
<<!
>>!!
Poll 관리 페이지가 이제 모양이 갖춰지는군요. 이제 모든 poll을 출력하는
"바꾸기 목록(change list)" 페이지를 좀더 바꿔보겠습니다.
<<!!

>>!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin04t.png
   :alt: Polls change list page
   :target: http://media.djangoproject.com/img/doc/tutorial/admin04.png
<<!
>>!!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin04t.png
   :alt: Poll 바꾸기 목록
   :target: http://media.djangoproject.com/img/doc/tutorial/admin04.png
<<!!

>>!
By default, Django displays the ``str()`` of each object. But sometimes it'd
be more helpful if we could display individual fields. To do that, use the
``list_display`` option, which is a tuple of field names to display, as columns,
on the change list page for the object::
<<!
>>!!
기본적으로 장고는 ``str()``을 통해서 객체를 화면에 출력합니다. 때때로
각각의 필드를 표시할 때 유용하게 사용할 수 있습니다. ``list_display``
옵션을 사용해서 튜플(tuple)로 필드 이름을 컬럼(columns)으로 표시할 수 있습니다.
<<!!

    class Poll(models.Model):
        # ...
        class Admin:
            # ...
            list_display = ('question', 'pub_date')

>>!
Just for good measure, let's also include the ``was_published_today`` custom
method from Tutorial 1::
<<!
>>!!
이전 페이지에서 설명한 ``was_published_today`` 메소드도
포함시켜봅니다.
<<!!

    list_display = ('question', 'pub_date', 'was_published_today')

>>!
Now the poll change list page looks like this:
<<!
>>!!
<<!!

>>!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin13t.png
   :alt: Polls change list page, updated
   :target: http://media.djangoproject.com/img/doc/tutorial/admin13.png
<<!
>>!!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin13t.png
   :alt: 바뀐 Poll 바꾸기 목록 페이지
   :target: http://media.djangoproject.com/img/doc/tutorial/admin13.png
<<!!

>>!
You can click on the column headers to sort by those values -- except in the
case of the ``was_published_today`` header, because sorting by the output of
an arbitrary method is not supported. Also note that the column header for
``was_published_today`` is, by default, the name of the method (with
underscores replaced with spaces). But you can change that by giving that
method a ``short_description`` attribute::
<<!
>>!!
<<!!

    def was_published_today(self):
        return self.pub_date.date() == datetime.date.today()
    was_published_today.short_description = 'Published today?'


>>!
Let's add another improvement to the Poll change list page: Filters. Add the
following line to ``Poll.Admin``::
<<!
>>!!
<<!!

    list_filter = ['pub_date']

>>!
That adds a "Filter" sidebar that lets people filter the change list by the
``pub_date`` field:
<<!
>>!!
<<!!

>>!
.. image:: http://media.djangoproject.com/img/doc/tutorial/admin14t.png
   :alt: Polls change list page, updated
   :target: http://media.djangoproject.com/img/doc/tutorial/admin14.png

>>!
The type of filter displayed depends on the type of field you're filtering on.
Because ``pub_date`` is a DateTimeField, Django knows to give the default
filter options for DateTimeFields: "Any date," "Today," "Past 7 days,"
"This month," "This year."

This is shaping up well. Let's add some search capability::
<<!
>>!!
<<!!

    search_fields = ['question']

>>!
That adds a search box at the top of the change list. When somebody enters
search terms, Django will search the ``question`` field. You can use as many
fields as you'd like -- although because it uses a ``LIKE`` query behind the
scenes, keep it reasonable, to keep your database happy.

Finally, because Poll objects have dates, it'd be convenient to be able to
drill down by date. Add this line::
<<!
>>!!
<<!!

    date_hierarchy = 'pub_date'

>>!
That adds hierarchical navigation, by date, to the top of the change list page.
At top level, it displays all available years. Then it drills down to months
and, ultimately, days.

Now's also a good time to note that change lists give you free pagination. The
default is to display 50 items per page. Change-list pagination, search boxes,
filters, date-hierarchies and column-header-ordering all work together like you
think they should.
<<!
>>!!
<<!!

>>!
Customize the admin look and feel
<<!
>>!!
<<!!
=================================

>>!
Clearly, having "Django administration" at the top of each admin page is
ridiculous. It's just placeholder text.

That's easy to change, though, using Django's template system. The Django admin
is powered by Django itself, and its interfaces use Django's own template
system. (How meta!)

Open your settings file (``mysite/settings.py``, remember) and look at the
``TEMPLATE_DIRS`` setting. ``TEMPLATE_DIRS`` is a tuple of filesystem
directories to check when loading Django templates. It's a search path.

By default, ``TEMPLATE_DIRS`` is empty. So, let's add a line to it, to tell
Django where our templates live::
<<!
>>!!
<<!!

    TEMPLATE_DIRS = (
        "/home/my_username/mytemplates", # Change this to your own directory.
    )

>>!
Now copy the template ``admin/base_site.html`` from within the default Django
admin template directory (``django/contrib/admin/templates``) into an ``admin``
subdirectory of whichever directory you're using in ``TEMPLATE_DIRS``. For
example, if your ``TEMPLATE_DIRS`` includes ``"/home/my_username/mytemplates"``,
as above, then copy ``django/contrib/admin/templates/admin/base_site.html`` to
``/home/my_username/mytemplates/admin/base_site.html``. Don't forget that
``admin`` subdirectory.

Then, just edit the file and replace the generic Django text with your own
site's name as you see fit.

Note that any of Django's default admin templates can be overridden. To
override a template, just do the same thing you did with ``base_site.html`` --
copy it from the default directory into your custom directory, and make
changes.

Astute readers will ask: But if ``TEMPLATE_DIRS`` was empty by default, how was
Django finding the default admin templates? The answer is that, by default,
Django automatically looks for a ``templates/`` subdirectory within each app
package, for use as a fallback. See the `loader types documentation`_ for full
information.
<<!
>>!!
<<!!

>>!
.. _loader types documentation: ../templates_python/#loader-types
<<!
>>!!
<<!!

>>!
Customize the admin index page
<<!
>>!!
<<!!
==============================

>>!
On a similar note, you might want to customize the look and feel of the Django
admin index page.

By default, it displays all available apps, according to your ``INSTALLED_APPS``
setting. But the order in which it displays things is random, and you may want
to make significant changes to the layout. After all, the index is probably the
most important page of the admin, and it should be easy to use.

The template to customize is ``admin/index.html``. (Do the same as with
``admin/base_site.html`` in the previous section -- copy it from the default
directory to your custom template directory.) Edit the file, and you'll see it
uses a template tag called ``{% get_admin_app_list as app_list %}``. That's the
magic that retrieves every installed Django app. Instead of using that, you can
hard-code links to object-specific admin pages in whatever way you think is
best.

Django offers another shortcut in this department. Run the command
``python manage.py adminindex polls`` to get a chunk of template code for
inclusion in the admin index template. It's a useful starting point.

For full details on customizing the look and feel of the Django admin site in
general, see the `Django admin CSS guide`_.

When you're comfortable with the admin site, read `part 3 of this tutorial`_ to
start working on public poll views.
<<!
>>!!
<<!!

>>!
.. _Django admin CSS guide: ../admin_css/
.. _part 3 of this tutorial: ../tutorial03/
<<!
>>!!
<<!!