~ubuntu-branches/ubuntu/quantal/python-django/quantal

« back to all changes in this revision

Viewing changes to docs/ref/contrib/admin.txt

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant
  • Date: 2008-11-15 19:15:33 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20081115191533-xbt1ut2xf4fvwtvc
Tags: 1.0.1-0ubuntu1
* New upstream release:
  - Bug fixes.

* The tests/ sub-directory appaers to have been dropped upstream, so pull
  our patch to workaround the tests and modify the rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
The Django admin site
5
5
=====================
6
6
 
 
7
.. module:: django.contrib.admin
 
8
   :synopsis: Django's admin site.
 
9
 
7
10
One of the most powerful parts of Django is the automatic admin interface. It
8
11
reads metadata in your model to provide a powerful and production-ready
9
12
interface that content producers can immediately use to start adding content to
41
44
 
42
45
The ``ModelAdmin`` class is the representation of a model in the admin
43
46
interface. These are stored in a file named ``admin.py`` in your application.
44
 
Let's take a look at a very simple example the ``ModelAdmin``::
 
47
Let's take a look at a very simple example of the ``ModelAdmin``::
45
48
 
46
49
    from django.contrib import admin
47
50
    from myproject.myapp.models import Author
50
53
        pass
51
54
    admin.site.register(Author, AuthorAdmin)
52
55
 
 
56
.. admonition:: Do you need a ``ModelAdmin`` object at all?
 
57
 
 
58
    In the preceding example, the ``ModelAdmin`` class doesn't define any
 
59
    custom values (yet). As a result, the default admin interface will be
 
60
    provided. If you are happy with the default admin interface, you don't
 
61
    need to define a ``ModelAdmin`` object at all -- you can register the
 
62
    model class without providing a ``ModelAdmin`` description. The
 
63
    preceding example could be simplified to::
 
64
 
 
65
        from django.contrib import admin
 
66
        from myproject.myapp.models import Author
 
67
    
 
68
        admin.site.register(Author)
 
69
    
53
70
``ModelAdmin`` Options
54
71
----------------------
55
72
 
145
162
            'classes': ['wide', 'extrapretty'],
146
163
            }
147
164
 
148
 
        Two useful classes defined by the default admin-site stylesheet are
 
165
        Two useful classes defined by the default admin site stylesheet are
149
166
        ``collapse`` and ``wide``. Fieldsets with the ``collapse`` style will
150
167
        be initially collapsed in the admin and replaced with a small
151
168
        "click to expand" link. Fieldsets with the ``wide`` style will be
245
262
      example::
246
263
    
247
264
          def upper_case_name(obj):
248
 
              return "%s %s" % (obj.first_name, obj.last_name).upper()
 
265
              return ("%s %s" % (obj.first_name, obj.last_name)).upper()
249
266
          upper_case_name.short_description = 'Name'
250
267
        
251
268
          class PersonAdmin(admin.ModelAdmin):
258
275
              list_display = ('upper_case_name',)
259
276
              
260
277
              def upper_case_name(self, obj):
261
 
                return "%s %s" % (obj.first_name, obj.last_name).upper()
 
278
                return ("%s %s" % (obj.first_name, obj.last_name)).upper()
262
279
              upper_case_name.short_description = 'Name'
263
280
    
264
281
    * A string representing an attribute on the model. This behaves almost
924
941
To continue the example above, we want to add a new link next to the ``History``
925
942
tool for the ``Page`` model. After looking at ``change_form.html`` we determine
926
943
that we only need to override the ``object-tools`` block. Therefore here is our
927
 
new ``change_form.html`` ::
 
944
new ``change_form.html`` :
 
945
 
 
946
.. code-block:: html+django
928
947
 
929
948
    {% extends "admin/change_form.html" %}
930
949
    {% load i18n %}