diff options
| author | Wiktor Kolodziej <wiktor@pykonik.org> | 2013-05-21 13:03:45 +0200 |
|---|---|---|
| committer | Florian Apolloner <florian@apolloner.eu> | 2013-05-21 13:19:18 +0200 |
| commit | cec9558fba1bc6401ea2ec6d71b816b4dfd31b28 (patch) | |
| tree | 25d82d122f1a3948085baf251f565ec54a029939 /docs | |
| parent | b1ac241ddc8e496fae9bee5e88511d5698c18ca5 (diff) | |
Fixed #17308 -- Enabled the use of short_description on properties in the admin.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/contrib/admin/index.txt | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt index 90570f9576..0aec62f7b9 100644 --- a/docs/ref/contrib/admin/index.txt +++ b/docs/ref/contrib/admin/index.txt @@ -464,7 +464,7 @@ subclass:: list_display = ('upper_case_name',) def upper_case_name(self, obj): - return ("%s %s" % (obj.first_name, obj.last_name)).upper() + return ("%s %s" % (obj.first_name, obj.last_name)).upper() upper_case_name.short_description = 'Name' * A string representing an attribute on the model. This behaves almost @@ -589,6 +589,27 @@ subclass:: The above will tell Django to order by the ``first_name`` field when trying to sort by ``colored_first_name`` in the admin. + * Elements of ``list_display`` can also be properties. Please note however, + that due to the way properties work in Python, setting + ``short_description`` on a property is only possible when using the + ``property()`` function and **not** with the ``@property`` decorator. + + For example:: + + class Person(object): + first_name = models.CharField(max_length=50) + last_name = models.CharField(max_length=50) + + def my_property(self): + return self.first_name + ' ' + self.last_name + my_property.short_description = "Full name of the person" + + full_name = property(my_property) + + class PersonAdmin(admin.ModelAdmin): + list_display = ('full_name',) + + * .. versionadded:: 1.6 The field names in ``list_display`` will also appear as CSS classes in |
