Ticket #14497: admin-filefield-readonly-display.diff

File admin-filefield-readonly-display.diff, 819 bytes (added by Adam J. Forster, 13 years ago)
  • django/contrib/admin/util.py

    diff --git a/django/contrib/admin/util.py b/django/contrib/admin/util.py
    index e98ec7b..174abb2 100644
    a b def display_for_field(value, field):  
    291291        return formats.number_format(value, field.decimal_places)
    292292    elif isinstance(field, models.FloatField):
    293293        return formats.number_format(value)
     294    elif isinstance(field, models.FileField):
     295        try:
     296            # Causes a ValueError if file is empty.
     297            value.file
     298            return mark_safe(u'<a href="%s">%s</a>'
     299                             % (escape(value.url),
     300                                escape(force_unicode(value))))
     301        except ValueError:
     302            return EMPTY_CHANGELIST_VALUE
    294303    else:
    295304        return smart_unicode(value)
    296305
Back to Top