diff options
Diffstat (limited to 'docs/admin.txt')
-rw-r--r-- | docs/admin.txt | 75 |
1 files changed, 51 insertions, 24 deletions
diff --git a/docs/admin.txt b/docs/admin.txt index dba28ecbdf..03c0154331 100644 --- a/docs/admin.txt +++ b/docs/admin.txt @@ -201,25 +201,36 @@ Example:: If you don't set ``list_display``, the admin site will display a single column that displays the ``__unicode__()`` representation of each object. -A few special cases to note about ``list_display``: - - * If the field is a ``ForeignKey``, Django will display the - ``__unicode__()`` of the related object. - - * ``ManyToManyField`` fields aren't supported, because that would entail - executing a separate SQL statement for each row in the table. If you - want to do this nonetheless, give your model a custom method, and add - that method's name to ``list_display``. (See below for more on custom - methods in ``list_display``.) - - * If the field is a ``BooleanField`` or ``NullBooleanField``, Django will - display a pretty "on" or "off" icon instead of ``True`` or ``False``. - - * If the string given is a method of the model, Django will call it and - display the output. This method should have a ``short_description`` - function attribute, for use as the header for the field. +You have four possible values that can be used in ``list_display``: - Here's a full example model:: + * A field of the model. For example:: + + class PersonAdmin(admin.ModelAdmin): + list_display = ('first_name', 'last_name') + + * A callable that accepts one parameter for the model instance. For + example:: + + def upper_case_name(obj): + return "%s %s" % (obj.first_name, obj.last_name).upper() + upper_case_name.short_description = 'Name' + + class PersonAdmin(admin.ModelAdmin): + list_display = (upper_case_name,) + + * A string representating an attribute on the ``ModelAdmin``. This behaves + the same as the callable. For example:: + + class PersonAdmin(admin.ModelAdmin): + list_display = ('upper_case_name',) + + def upper_case_name(self, obj): + return "%s %s" % (obj.first_name, obj.last_name).upper() + upper_case_name.short_description = 'Name' + + * A string representating an attribute on the model. This behaves almost + the same as the callable, but ``self`` in this context is the model + instance. Here's a full model example:: class Person(models.Model): name = models.CharField(max_length=50) @@ -232,10 +243,25 @@ A few special cases to note about ``list_display``: class PersonAdmin(admin.ModelAdmin): list_display = ('name', 'decade_born_in') - * If the string given is a method of the model, Django will HTML-escape the - output by default. If you'd rather not escape the output of the method, - give the method an ``allow_tags`` attribute whose value is ``True``. +A few special cases to note about ``list_display``: + + * If the field is a ``ForeignKey``, Django will display the + ``__unicode__()`` of the related object. + + * ``ManyToManyField`` fields aren't supported, because that would entail + executing a separate SQL statement for each row in the table. If you + want to do this nonetheless, give your model a custom method, and add + that method's name to ``list_display``. (See below for more on custom + methods in ``list_display``.) + + * If the field is a ``BooleanField`` or ``NullBooleanField``, Django will + display a pretty "on" or "off" icon instead of ``True`` or ``False``. + * If the string given is a method of the model, ``ModelAdmin`` or a + callable, Django will HTML-escape the output by default. If you'd rather + not escape the output of the method, give the method an ``allow_tags`` + attribute whose value is ``True``. + Here's a full example model:: class Person(models.Model): @@ -250,9 +276,10 @@ A few special cases to note about ``list_display``: class PersonAdmin(admin.ModelAdmin): list_display = ('first_name', 'last_name', 'colored_name') - * If the string given is a method of the model that returns True or False - Django will display a pretty "on" or "off" icon if you give the method a - ``boolean`` attribute whose value is ``True``. + * If the string given is a method of the model, ``ModelAdmin`` or a + callable that returns True or False Django will display a pretty "on" or + "off" icon if you give the method a ``boolean`` attribute whose value is + ``True``. Here's a full example model:: |