Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

magic-removal: Fixed #1326 -- Allowed model properties in list_displa…

…y. Thanks, Kieran Holland

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2268 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c2e2893460bd90d3f453ad2295a02eb5cc0a1bde 1 parent 6aff90c
Adrian Holovaty authored February 04, 2006
18  django/contrib/admin/templatetags/admin_list.py
@@ -80,11 +80,11 @@ def result_headers(cl):
80 80
             if field_name == '__repr__':
81 81
                 header = lookup_opts.verbose_name
82 82
             else:
83  
-                func = getattr(cl.model, field_name) # Let AttributeErrors propogate.
  83
+                attr = getattr(cl.model, field_name) # Let AttributeErrors propogate.
84 84
                 try:
85  
-                    header = func.short_description
  85
+                    header = attr.short_description
86 86
                 except AttributeError:
87  
-                    header = func.__name__.replace('_', ' ')
  87
+                    header = field_name.replace('_', ' ')
88 88
             # Non-field list_display values don't get ordering capability.
89 89
             yield {"text": header}
90 90
         else:
@@ -110,17 +110,19 @@ def items_for_result(cl, result):
110 110
         try:
111 111
             f = cl.lookup_opts.get_field(field_name)
112 112
         except models.FieldDoesNotExist:
113  
-            # For non-field list_display values, the value is a method
114  
-            # name. Execute the method.
  113
+            # For non-field list_display values, the value is either a method
  114
+            # or a property.
115 115
             try:
116  
-                func = getattr(result, field_name)
117  
-                result_repr = str(func())
  116
+                attr = getattr(result, field_name)
  117
+                if callable(attr):
  118
+                    attr = attr()
  119
+                result_repr = str(attr)
118 120
             except AttributeError, ObjectDoesNotExist:
119 121
                 result_repr = EMPTY_CHANGELIST_VALUE
120 122
             else:
121 123
                 # Strip HTML tags in the resulting text, except if the
122 124
                 # function has an "allow_tags" attribute set to True.
123  
-                if not getattr(func, 'allow_tags', False):
  125
+                if not getattr(attr, 'allow_tags', False):
124 126
                     result_repr = escape(result_repr)
125 127
         else:
126 128
             field_val = getattr(result, f.attname)
4  django/core/management.py
@@ -889,8 +889,8 @@ def get_validation_errors(outfile):
889 889
                         try:
890 890
                             f = opts.get_field(fn)
891 891
                         except models.FieldDoesNotExist:
892  
-                            if not hasattr(cls, fn) or not callable(getattr(cls, fn)):
893  
-                                e.add(opts, '"admin.list_display" refers to %r, which isn\'t a field or method.' % fn)
  892
+                            if not hasattr(cls, fn):
  893
+                                e.add(opts, '"admin.list_display" refers to %r, which isn\'t an attribute, method or property.' % fn)
894 894
                         else:
895 895
                             if isinstance(f, models.ManyToManyField):
896 896
                                 e.add(opts, '"admin.list_display" doesn\'t support ManyToManyFields (%r).' % fn)

0 notes on commit c2e2893

Please sign in to comment.
Something went wrong with that request. Please try again.