summaryrefslogtreecommitdiff
path: root/django/contrib/admin
diff options
context:
space:
mode:
authorWiktor Kolodziej <wiktor@pykonik.org>2013-05-21 13:03:45 +0200
committerFlorian Apolloner <florian@apolloner.eu>2013-05-21 13:19:18 +0200
commitcec9558fba1bc6401ea2ec6d71b816b4dfd31b28 (patch)
tree25d82d122f1a3948085baf251f565ec54a029939 /django/contrib/admin
parentb1ac241ddc8e496fae9bee5e88511d5698c18ca5 (diff)
Fixed #17308 -- Enabled the use of short_description on properties in the admin.
Diffstat (limited to 'django/contrib/admin')
-rw-r--r--django/contrib/admin/util.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/django/contrib/admin/util.py b/django/contrib/admin/util.py
index 97858e688e..078adbe827 100644
--- a/django/contrib/admin/util.py
+++ b/django/contrib/admin/util.py
@@ -269,8 +269,9 @@ def lookup_field(name, obj, model_admin=None):
def label_for_field(name, model, model_admin=None, return_attr=False):
"""
- Returns a sensible label for a field name. The name can be a callable or the
- name of an object attributes, as well as a genuine fields. If return_attr is
+ Returns a sensible label for a field name. The name can be a callable,
+ property (but not created with @property decorator) or the name of an
+ object's attribute, as well as a genuine fields. If return_attr is
True, the resolved attribute (which could be a callable) is also returned.
This will be None if (and only if) the name refers to a field.
"""
@@ -303,6 +304,10 @@ def label_for_field(name, model, model_admin=None, return_attr=False):
if hasattr(attr, "short_description"):
label = attr.short_description
+ elif (isinstance(attr, property) and
+ hasattr(attr, "fget") and
+ hasattr(attr.fget, "short_description")):
+ label = attr.fget.short_description
elif callable(attr):
if attr.__name__ == "<lambda>":
label = "--"
@@ -315,6 +320,7 @@ def label_for_field(name, model, model_admin=None, return_attr=False):
else:
return label
+
def help_text_for_field(name, model):
try:
help_text = model._meta.get_field_by_name(name)[0].help_text