From 07cfe1bd822f4108b5029aef1615a17000d0b0dc Mon Sep 17 00:00:00 2001 From: Collin Anderson Date: Wed, 11 Feb 2015 11:40:03 -0500 Subject: [PATCH] Refs #14497 -- Handled empty readonly admin FileFields --- django/contrib/admin/utils.py | 2 +- tests/admin_widgets/tests.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/django/contrib/admin/utils.py b/django/contrib/admin/utils.py index f704ef3af7..00d8b41129 100644 --- a/django/contrib/admin/utils.py +++ b/django/contrib/admin/utils.py @@ -388,7 +388,7 @@ def display_for_field(value, field): return formats.number_format(value, field.decimal_places) elif isinstance(field, models.FloatField): return formats.number_format(value) - elif isinstance(field, models.FileField): + elif isinstance(field, models.FileField) and value: return mark_safe('%s' % ( conditional_escape(value.url), conditional_escape(value), diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py index cfe0c07e70..17d0ed44c0 100644 --- a/tests/admin_widgets/tests.py +++ b/tests/admin_widgets/tests.py @@ -396,6 +396,12 @@ class AdminFileWidgetTests(DjangoTestCase): '', html=True, ) + response = self.client.get(reverse('admin:admin_widgets_album_add')) + self.assertContains( + response, + '

', + html=True, + ) @override_settings(ROOT_URLCONF='admin_widgets.urls')