Code

Changes between Version 1 and Version 2 of DjangoDocumentKoreanTranslation/tutorial02.txt


Ignore:
Timestamp:
11/26/07 06:30:19 (6 years ago)
Author:
spike
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DjangoDocumentKoreanTranslation/tutorial02.txt

    v1 v2  
    376376<<! 
    377377>>!! 
    378 폼을 좀 바꿔볼까요? ``Admin``에 ``fields`` 항목을 추가해서 표시되는 필드의 순서를 바꿀 수 있습니다. 
     378폼을 좀 바꿔볼까요? ``Admin``에 ``fields`` 항목을 추가해서 표시되는 
     379필드의 순서를 바꿀 수 있습니다.:: 
    379380<<!! 
    380381 
     
    414415<<! 
    415416>>!! 
    416 필드수를 적절히 나누고 싶다면 필드셋(fieldsets)으로 나눌 수 있습니다. 
     417필드수를 적절히 나누고 싶다면 필드셋(fieldsets)으로 나눌 수 있습니다.:: 
    417418<<!! 
    418419 
     
    687688기본적으로 장고는 ``str()``을 통해서 객체를 화면에 출력합니다. 때때로 
    688689각각의 필드를 표시할 때 유용하게 사용할 수 있습니다. ``list_display`` 
    689 옵션을 사용해서 튜플(tuple)로 필드 이름을 컬럼(columns)으로 표시할 수 있습니다. 
     690옵션을 사용해서 튜플(tuple)로 필드 이름을 컬럼(columns)으로 표시할 수 
     691있습니다.:: 
    690692<<!! 
    691693 
     
    711713<<! 
    712714>>!! 
     715이제 Poll change list가 아래와 같이 보입니다.: 
    713716<<!! 
    714717 
     
    733736<<! 
    734737>>!! 
     738이제 컬럼 제목을 눌러서 이 값들을 정렬할 수 있습니다. -- 
     739``was_published_today``는 아닙니다. 왜냐하면 메소드의 결과는 정렬할 수 
     740없기 때문입니다. 하지만 ``short_description`` 속성을 추가해서 바꿀 수 
     741있습니다.:: 
    735742<<!! 
    736743 
     
    745752<<! 
    746753>>!! 
     754Poll change list이 점점 개선되어 가는군요: 이제 필터(Filters)를 
     755추가해봅니다. ``Poll.Admin``에 다음을 추가해봅니다.:: 
    747756<<!! 
    748757 
     
    754763<<! 
    755764>>!! 
     765이것은 사이드바에 ``pub_date``별로 change list를 걸러서 표시해주는 
     766"필터"를 추가합니다. 
    756767<<!! 
    757768 
     
    760771   :alt: Polls change list page, updated 
    761772   :target: http://media.djangoproject.com/img/doc/tutorial/admin14.png 
     773<<! 
     774>>!! 
     775.. image:: http://media.djangoproject.com/img/doc/tutorial/admin14t.png 
     776   :alt: 개선된 Polls change list 페이지 
     777   :target: http://media.djangoproject.com/img/doc/tutorial/admin14.png 
     778<<!! 
    762779 
    763780>>! 
     
    770787<<! 
    771788>>!! 
     789The type of filter displayed depends on the type of field you're filtering on. 
     790Because ``pub_date`` is a DateTimeField, Django knows to give the default 
     791filter options for DateTimeFields: "Any date," "Today," "Past 7 days," 
     792"This month," "This year." 
     793 
     794This is shaping up well. Let's add some search capability:: 
    772795<<!! 
    773796 
     
    784807<<! 
    785808>>!! 
     809That adds a search box at the top of the change list. When somebody enters 
     810search terms, Django will search the ``question`` field. You can use as many 
     811fields as you'd like -- although because it uses a ``LIKE`` query behind the 
     812scenes, keep it reasonable, to keep your database happy. 
     813 
     814Finally, because Poll objects have dates, it'd be convenient to be able to 
     815drill down by date. Add this line:: 
    786816<<!! 
    787817 
     
    799829<<! 
    800830>>!! 
     831That adds hierarchical navigation, by date, to the top of the change list page. 
     832At top level, it displays all available years. Then it drills down to months 
     833and, ultimately, days. 
     834 
     835Now's also a good time to note that change lists give you free pagination. The 
     836default is to display 50 items per page. Change-list pagination, search boxes, 
     837filters, date-hierarchies and column-header-ordering all work together like you 
     838think they should. 
    801839<<!! 
    802840 
     
    805843<<! 
    806844>>!! 
     845Customize the admin look and feel 
    807846<<!! 
    808847================================= 
     
    824863<<! 
    825864>>!! 
     865Clearly, having "Django administration" at the top of each admin page is 
     866ridiculous. It's just placeholder text. 
     867 
     868That's easy to change, though, using Django's template system. The Django admin 
     869is powered by Django itself, and its interfaces use Django's own template 
     870system. (How meta!) 
     871 
     872Open your settings file (``mysite/settings.py``, remember) and look at the 
     873``TEMPLATE_DIRS`` setting. ``TEMPLATE_DIRS`` is a tuple of filesystem 
     874directories to check when loading Django templates. It's a search path. 
     875 
     876By default, ``TEMPLATE_DIRS`` is empty. So, let's add a line to it, to tell 
     877Django where our templates live:: 
    826878<<!! 
    827879 
     
    854906<<! 
    855907>>!! 
     908Now copy the template ``admin/base_site.html`` from within the default Django 
     909admin template directory (``django/contrib/admin/templates``) into an ``admin`` 
     910subdirectory of whichever directory you're using in ``TEMPLATE_DIRS``. For 
     911example, if your ``TEMPLATE_DIRS`` includes ``"/home/my_username/mytemplates"``, 
     912as above, then copy ``django/contrib/admin/templates/admin/base_site.html`` to 
     913``/home/my_username/mytemplates/admin/base_site.html``. Don't forget that 
     914``admin`` subdirectory. 
     915 
     916Then, just edit the file and replace the generic Django text with your own 
     917site's name as you see fit. 
     918 
     919Note that any of Django's default admin templates can be overridden. To 
     920override a template, just do the same thing you did with ``base_site.html`` -- 
     921copy it from the default directory into your custom directory, and make 
     922changes. 
     923 
     924Astute readers will ask: But if ``TEMPLATE_DIRS`` was empty by default, how was 
     925Django finding the default admin templates? The answer is that, by default, 
     926Django automatically looks for a ``templates/`` subdirectory within each app 
     927package, for use as a fallback. See the `loader types documentation`_ for full 
     928information. 
    856929<<!! 
    857930 
     
    860933<<! 
    861934>>!! 
     935.. _loader types documentation: ../templates_python/#loader-types 
    862936<<!! 
    863937 
     
    866940<<! 
    867941>>!! 
     942Customize the admin index page 
    868943<<!! 
    869944============================== 
     
    897972<<! 
    898973>>!! 
     974On a similar note, you might want to customize the look and feel of the Django 
     975admin index page. 
     976 
     977By default, it displays all available apps, according to your ``INSTALLED_APPS`` 
     978setting. But the order in which it displays things is random, and you may want 
     979to make significant changes to the layout. After all, the index is probably the 
     980most important page of the admin, and it should be easy to use. 
     981 
     982The template to customize is ``admin/index.html``. (Do the same as with 
     983``admin/base_site.html`` in the previous section -- copy it from the default 
     984directory to your custom template directory.) Edit the file, and you'll see it 
     985uses a template tag called ``{% get_admin_app_list as app_list %}``. That's the 
     986magic that retrieves every installed Django app. Instead of using that, you can 
     987hard-code links to object-specific admin pages in whatever way you think is 
     988best. 
     989 
     990Django offers another shortcut in this department. Run the command 
     991``python manage.py adminindex polls`` to get a chunk of template code for 
     992inclusion in the admin index template. It's a useful starting point. 
     993 
     994For full details on customizing the look and feel of the Django admin site in 
     995general, see the `Django admin CSS guide`_. 
     996 
     997When you're comfortable with the admin site, read `part 3 of this tutorial`_ to 
     998start working on public poll views. 
    899999<<!! 
    9001000 
     
    9041004<<! 
    9051005>>!! 
     1006.. _Django admin CSS guide: ../admin_css/ 
     1007.. _part 3 of this tutorial: ../tutorial03/ 
    9061008<<!! 
    9071009}}}