mirror of
https://github.com/django/django.git
synced 2025-06-05 03:29:12 +00:00
magic-removal: Fixed #1326 -- Allowed model properties in list_display. Thanks, Kieran Holland
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2268 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
6aff90c1ba
commit
c2e2893460
@ -80,11 +80,11 @@ def result_headers(cl):
|
|||||||
if field_name == '__repr__':
|
if field_name == '__repr__':
|
||||||
header = lookup_opts.verbose_name
|
header = lookup_opts.verbose_name
|
||||||
else:
|
else:
|
||||||
func = getattr(cl.model, field_name) # Let AttributeErrors propogate.
|
attr = getattr(cl.model, field_name) # Let AttributeErrors propogate.
|
||||||
try:
|
try:
|
||||||
header = func.short_description
|
header = attr.short_description
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
header = func.__name__.replace('_', ' ')
|
header = field_name.replace('_', ' ')
|
||||||
# Non-field list_display values don't get ordering capability.
|
# Non-field list_display values don't get ordering capability.
|
||||||
yield {"text": header}
|
yield {"text": header}
|
||||||
else:
|
else:
|
||||||
@ -110,17 +110,19 @@ def items_for_result(cl, result):
|
|||||||
try:
|
try:
|
||||||
f = cl.lookup_opts.get_field(field_name)
|
f = cl.lookup_opts.get_field(field_name)
|
||||||
except models.FieldDoesNotExist:
|
except models.FieldDoesNotExist:
|
||||||
# For non-field list_display values, the value is a method
|
# For non-field list_display values, the value is either a method
|
||||||
# name. Execute the method.
|
# or a property.
|
||||||
try:
|
try:
|
||||||
func = getattr(result, field_name)
|
attr = getattr(result, field_name)
|
||||||
result_repr = str(func())
|
if callable(attr):
|
||||||
|
attr = attr()
|
||||||
|
result_repr = str(attr)
|
||||||
except AttributeError, ObjectDoesNotExist:
|
except AttributeError, ObjectDoesNotExist:
|
||||||
result_repr = EMPTY_CHANGELIST_VALUE
|
result_repr = EMPTY_CHANGELIST_VALUE
|
||||||
else:
|
else:
|
||||||
# Strip HTML tags in the resulting text, except if the
|
# Strip HTML tags in the resulting text, except if the
|
||||||
# function has an "allow_tags" attribute set to True.
|
# function has an "allow_tags" attribute set to True.
|
||||||
if not getattr(func, 'allow_tags', False):
|
if not getattr(attr, 'allow_tags', False):
|
||||||
result_repr = escape(result_repr)
|
result_repr = escape(result_repr)
|
||||||
else:
|
else:
|
||||||
field_val = getattr(result, f.attname)
|
field_val = getattr(result, f.attname)
|
||||||
|
@ -889,8 +889,8 @@ def get_validation_errors(outfile):
|
|||||||
try:
|
try:
|
||||||
f = opts.get_field(fn)
|
f = opts.get_field(fn)
|
||||||
except models.FieldDoesNotExist:
|
except models.FieldDoesNotExist:
|
||||||
if not hasattr(cls, fn) or not callable(getattr(cls, fn)):
|
if not hasattr(cls, fn):
|
||||||
e.add(opts, '"admin.list_display" refers to %r, which isn\'t a field or method.' % fn)
|
e.add(opts, '"admin.list_display" refers to %r, which isn\'t an attribute, method or property.' % fn)
|
||||||
else:
|
else:
|
||||||
if isinstance(f, models.ManyToManyField):
|
if isinstance(f, models.ManyToManyField):
|
||||||
e.add(opts, '"admin.list_display" doesn\'t support ManyToManyFields (%r).' % fn)
|
e.add(opts, '"admin.list_display" doesn\'t support ManyToManyFields (%r).' % fn)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user