2005-07-16 22:41:31 +08:00
|
|
|
======================================
|
|
|
|
Customizing the Django admin interface
|
|
|
|
======================================
|
2005-07-15 23:57:46 +08:00
|
|
|
|
2008-08-24 06:25:40 +08:00
|
|
|
.. warning::
|
|
|
|
|
|
|
|
The design of the admin has changed somewhat since this document was
|
|
|
|
written, and parts may not apply any more. This document is no longer
|
|
|
|
maintained since an official API for customizing the Django admin interface
|
|
|
|
is in development.
|
|
|
|
|
2005-07-15 23:57:46 +08:00
|
|
|
Django's dynamic admin interface gives you a fully-functional admin for free
|
|
|
|
with no hand-coding required. The dynamic admin is designed to be
|
|
|
|
production-ready, not just a starting point, so you can use it as-is on a real
|
|
|
|
site. While the underlying format of the admin pages is built in to Django, you
|
|
|
|
can customize the look and feel by editing the admin stylesheet and images.
|
|
|
|
|
|
|
|
Here's a quick and dirty overview some of the main styles and classes used in
|
|
|
|
the Django admin CSS.
|
|
|
|
|
|
|
|
Modules
|
|
|
|
=======
|
|
|
|
|
|
|
|
The ``.module`` class is a basic building block for grouping content in the
|
2005-07-17 06:19:10 +08:00
|
|
|
admin. It's generally applied to a ``div`` or a ``fieldset``. It wraps the content
|
2005-07-15 23:57:46 +08:00
|
|
|
group in a box and applies certain styles to the elements within. An ``h2``
|
|
|
|
within a ``div.module`` will align to the top of the ``div`` as a header for the
|
|
|
|
whole group.
|
|
|
|
|
Fixed a whole bunch of small docs typos, errors, and ommissions.
Fixes #8358, #8396, #8724, #9043, #9128, #9247, #9267, #9267, #9375, #9409, #9414, #9416, #9446, #9454, #9464, #9503, #9518, #9533, #9657, #9658, #9683, #9733, #9771, #9835, #9836, #9837, #9897, #9906, #9912, #9945, #9986, #9992, #10055, #10084, #10091, #10145, #10245, #10257, #10309, #10358, #10359, #10424, #10426, #10508, #10531, #10551, #10635, #10637, #10656, #10658, #10690, #10699, #19528.
Thanks to all the respective authors of those tickets.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10371 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-04-04 02:30:54 +08:00
|
|
|
.. image:: _images/module.png
|
2005-07-19 23:39:15 +08:00
|
|
|
:alt: Example use of module class on admin homepage
|
|
|
|
|
2005-07-15 23:57:46 +08:00
|
|
|
Column Types
|
|
|
|
============
|
|
|
|
|
2008-08-24 06:25:40 +08:00
|
|
|
.. note::
|
2006-02-03 01:35:00 +08:00
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
All admin pages (except the dashboard) are fluid-width. All fixed-width
|
|
|
|
classes from previous Django versions have been removed.
|
2006-02-03 01:35:00 +08:00
|
|
|
|
2005-07-15 23:57:46 +08:00
|
|
|
The base template for each admin page has a block that defines the column
|
|
|
|
structure for the page. This sets a class on the page content area
|
2006-05-02 09:31:56 +08:00
|
|
|
(``div#content``) so everything on the page knows how wide it should be. There
|
|
|
|
are three column types available.
|
2005-07-15 23:57:46 +08:00
|
|
|
|
|
|
|
colM
|
|
|
|
This is the default column setting for all pages. The "M" stands for "main".
|
|
|
|
Assumes that all content on the page is in one main column
|
|
|
|
(``div#content-main``).
|
|
|
|
colMS
|
|
|
|
This is for pages with one main column and a sidebar on the right. The "S"
|
|
|
|
stands for "sidebar". Assumes that main content is in ``div#content-main``
|
|
|
|
and sidebar content is in ``div#content-related``. This is used on the main
|
|
|
|
admin page.
|
|
|
|
colSM
|
|
|
|
Same as above, with the sidebar on the left. The source order of the columns
|
|
|
|
doesn't matter.
|
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
For instance, you could stick this in a template to make a two-column page with
|
2008-08-24 06:25:40 +08:00
|
|
|
the sidebar on the right:
|
|
|
|
|
|
|
|
.. code-block:: html+django
|
2005-07-15 23:57:46 +08:00
|
|
|
|
2006-02-03 01:35:00 +08:00
|
|
|
{% block coltype %}colMS{% endblock %}
|
2005-07-15 23:57:46 +08:00
|
|
|
|
|
|
|
Text Styles
|
|
|
|
===========
|
|
|
|
|
|
|
|
Font Sizes
|
|
|
|
----------
|
|
|
|
|
|
|
|
Most HTML elements (headers, lists, etc.) have base font sizes in the stylesheet
|
|
|
|
based on context. There are three classes are available for forcing text to a
|
|
|
|
certain size in any context.
|
|
|
|
|
|
|
|
small
|
|
|
|
11px
|
|
|
|
tiny
|
|
|
|
10px
|
|
|
|
mini
|
|
|
|
9px (use sparingly)
|
|
|
|
|
|
|
|
Font Styles and Alignment
|
|
|
|
-------------------------
|
|
|
|
|
|
|
|
There are also a few styles for styling text.
|
|
|
|
|
|
|
|
.quiet
|
|
|
|
Sets font color to light gray. Good for side notes in instructions. Combine
|
|
|
|
with ``.small`` or ``.tiny`` for sheer excitement.
|
|
|
|
.help
|
|
|
|
This is a custom class for blocks of inline help text explaining the
|
|
|
|
function of form elements. It makes text smaller and gray, and when applied
|
2006-09-29 10:30:42 +08:00
|
|
|
to ``p`` elements within ``.form-row`` elements (see Form Styles below),
|
2006-05-02 09:31:56 +08:00
|
|
|
it will offset the text to align with the form field. Use this for help
|
|
|
|
text, instead of ``small quiet``. It works on other elements, but try to
|
|
|
|
put the class on a ``p`` whenever you can.
|
2005-07-15 23:57:46 +08:00
|
|
|
.align-left
|
2006-05-02 09:31:56 +08:00
|
|
|
It aligns the text left. Only works on block elements containing inline
|
|
|
|
elements.
|
2005-07-15 23:57:46 +08:00
|
|
|
.align-right
|
|
|
|
Are you paying attention?
|
|
|
|
.nowrap
|
2006-05-02 09:31:56 +08:00
|
|
|
Keeps text and inline objects from wrapping. Comes in handy for table
|
|
|
|
headers you want to stay on one line.
|
2005-07-15 23:57:46 +08:00
|
|
|
|
|
|
|
Floats and Clears
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
float-left
|
|
|
|
floats left
|
|
|
|
float-right
|
|
|
|
floats right
|
|
|
|
clear
|
|
|
|
clears all
|
|
|
|
|
|
|
|
Object Tools
|
|
|
|
============
|
|
|
|
|
|
|
|
Certain actions which apply directly to an object are used in form and
|
|
|
|
changelist pages. These appear in a "toolbar" row above the form or changelist,
|
|
|
|
to the right of the page. The tools are wrapped in a ``ul`` with the class
|
|
|
|
``object-tools``. There are two custom tool types which can be defined with an
|
|
|
|
additional class on the ``a`` for that tool. These are ``.addlink`` and
|
|
|
|
``.viewsitelink``.
|
|
|
|
|
2008-08-24 06:25:40 +08:00
|
|
|
Example from a changelist page:
|
|
|
|
|
|
|
|
.. code-block:: html+django
|
2005-07-15 23:57:46 +08:00
|
|
|
|
2005-07-17 06:19:10 +08:00
|
|
|
<ul class="object-tools">
|
2006-07-22 04:48:17 +08:00
|
|
|
<li><a href="/stories/add/" class="addlink">Add redirect</a></li>
|
|
|
|
</ul>
|
2005-11-29 22:43:07 +08:00
|
|
|
|
Fixed a whole bunch of small docs typos, errors, and ommissions.
Fixes #8358, #8396, #8724, #9043, #9128, #9247, #9267, #9267, #9375, #9409, #9414, #9416, #9446, #9454, #9464, #9503, #9518, #9533, #9657, #9658, #9683, #9733, #9771, #9835, #9836, #9837, #9897, #9906, #9912, #9945, #9986, #9992, #10055, #10084, #10091, #10145, #10245, #10257, #10309, #10358, #10359, #10424, #10426, #10508, #10531, #10551, #10635, #10637, #10656, #10658, #10690, #10699, #19528.
Thanks to all the respective authors of those tickets.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10371 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-04-04 02:30:54 +08:00
|
|
|
.. image:: _images/objecttools_01.png
|
2005-07-19 23:39:15 +08:00
|
|
|
:alt: Object tools on a changelist page
|
2005-07-15 23:57:46 +08:00
|
|
|
|
2008-08-24 06:25:40 +08:00
|
|
|
and from a form page:
|
|
|
|
|
|
|
|
.. code-block:: html+django
|
2005-07-15 23:57:46 +08:00
|
|
|
|
|
|
|
<ul class="object-tools">
|
|
|
|
<li><a href="/history/303/152383/">History</a></li>
|
|
|
|
<li><a href="/r/303/152383/" class="viewsitelink">View on site</a></li>
|
|
|
|
</ul>
|
|
|
|
|
Fixed a whole bunch of small docs typos, errors, and ommissions.
Fixes #8358, #8396, #8724, #9043, #9128, #9247, #9267, #9267, #9375, #9409, #9414, #9416, #9446, #9454, #9464, #9503, #9518, #9533, #9657, #9658, #9683, #9733, #9771, #9835, #9836, #9837, #9897, #9906, #9912, #9945, #9986, #9992, #10055, #10084, #10091, #10145, #10245, #10257, #10309, #10358, #10359, #10424, #10426, #10508, #10531, #10551, #10635, #10637, #10656, #10658, #10690, #10699, #19528.
Thanks to all the respective authors of those tickets.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10371 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-04-04 02:30:54 +08:00
|
|
|
.. image:: _images/objecttools_02.png
|
2005-07-19 23:39:15 +08:00
|
|
|
:alt: Object tools on a form page
|
|
|
|
|
2005-07-15 23:57:46 +08:00
|
|
|
Form Styles
|
|
|
|
===========
|
|
|
|
|
|
|
|
Fieldsets
|
|
|
|
---------
|
|
|
|
|
2005-07-17 06:19:10 +08:00
|
|
|
Admin forms are broken up into groups by ``fieldset`` elements. Each form fieldset
|
|
|
|
should have a class ``.module``. Each fieldset should have a header ``h2`` within the
|
|
|
|
fieldset at the top (except the first group in the form, and in some cases where the
|
|
|
|
group of fields doesn't have a logical label).
|
2005-07-15 23:57:46 +08:00
|
|
|
|
|
|
|
Each fieldset can also take extra classes in addition to ``.module`` to apply
|
|
|
|
appropriate formatting to the group of fields.
|
|
|
|
|
|
|
|
.aligned
|
2006-05-02 09:31:56 +08:00
|
|
|
This will align the labels and inputs side by side on the same line.
|
2005-07-15 23:57:46 +08:00
|
|
|
.wide
|
2006-05-02 09:31:56 +08:00
|
|
|
Used in combination with ``.aligned`` to widen the space available for the
|
|
|
|
labels.
|
2005-07-15 23:57:46 +08:00
|
|
|
|
|
|
|
Form Rows
|
|
|
|
---------
|
|
|
|
|
|
|
|
Each row of the form (within the ``fieldset``) should be enclosed in a ``div``
|
|
|
|
with class ``form-row``. If the field in the row is required, a class of
|
2005-07-19 23:39:15 +08:00
|
|
|
``required`` should also be added to the ``div.form-row``.
|
|
|
|
|
Fixed a whole bunch of small docs typos, errors, and ommissions.
Fixes #8358, #8396, #8724, #9043, #9128, #9247, #9267, #9267, #9375, #9409, #9414, #9416, #9446, #9454, #9464, #9503, #9518, #9533, #9657, #9658, #9683, #9733, #9771, #9835, #9836, #9837, #9897, #9906, #9912, #9945, #9986, #9992, #10055, #10084, #10091, #10145, #10245, #10257, #10309, #10358, #10359, #10424, #10426, #10508, #10531, #10551, #10635, #10637, #10656, #10658, #10690, #10699, #19528.
Thanks to all the respective authors of those tickets.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10371 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-04-04 02:30:54 +08:00
|
|
|
.. image:: _images/formrow.png
|
2005-07-19 23:39:15 +08:00
|
|
|
:alt: Example use of form-row class
|
2005-07-15 23:57:46 +08:00
|
|
|
|
|
|
|
Labels
|
|
|
|
------
|
|
|
|
|
2005-07-19 23:31:05 +08:00
|
|
|
Form labels should always precede the field, except in the case
|
|
|
|
of checkboxes and radio buttons, where the ``input`` should come first. Any
|
|
|
|
explanation or help text should follow the ``label`` in a ``p`` with class
|
2006-09-29 10:30:42 +08:00
|
|
|
``.help``.
|