From cec9558fba1bc6401ea2ec6d71b816b4dfd31b28 Mon Sep 17 00:00:00 2001 From: Wiktor Kolodziej Date: Tue, 21 May 2013 13:03:45 +0200 Subject: Fixed #17308 -- Enabled the use of short_description on properties in the admin. --- django/contrib/admin/util.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'django') 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__ == "": 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 -- cgit v1.3