mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #17308 -- Enabled the use of short_description on properties in the admin.
This commit is contained in:
committed by
Florian Apolloner
parent
b1ac241ddc
commit
cec9558fba
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user