diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py index 13c7c9cf01..2bfbc9715d 100644 --- a/django/contrib/admin/widgets.py +++ b/django/contrib/admin/widgets.py @@ -84,7 +84,7 @@ class AdminFileWidget(forms.FileInput): def render(self, name, value, attrs=None): output = [] - if value: + if value and hasattr(value, "url"): output.append('%s %s
%s ' % \ (_('Currently:'), value.url, value, _('Change:'))) output.append(super(AdminFileWidget, self).render(name, value, attrs)) diff --git a/tests/regressiontests/admin_widgets/models.py b/tests/regressiontests/admin_widgets/models.py index af72422849..e178a750e3 100644 --- a/tests/regressiontests/admin_widgets/models.py +++ b/tests/regressiontests/admin_widgets/models.py @@ -27,6 +27,7 @@ class Album(models.Model): __test__ = {'WIDGETS_TESTS': """ >>> from datetime import datetime >>> from django.utils.html import escape, conditional_escape +>>> from django.core.files.uploadedfile import SimpleUploadedFile >>> from django.contrib.admin.widgets import FilteredSelectMultiple, AdminSplitDateTime >>> from django.contrib.admin.widgets import AdminFileWidget, ForeignKeyRawIdWidget, ManyToManyRawIdWidget >>> from django.contrib.admin.widgets import RelatedFieldWidgetWrapper @@ -54,6 +55,8 @@ HTML escaped. >>> w = AdminFileWidget() >>> print conditional_escape(w.render('test', album.cover_art)) Currently: albums\hybrid_theory.jpg
Change: +>>> print conditional_escape(w.render('test', SimpleUploadedFile('test', 'content'))) + >>> rel = Album._meta.get_field('band').rel >>> w = ForeignKeyRawIdWidget(rel)