diff --git a/django/contrib/admin/templates/admin/widgets/clearable_file_input.html b/django/contrib/admin/templates/admin/widgets/clearable_file_input.html index 80699d1a50..fe71ebdb06 100644 --- a/django/contrib/admin/templates/admin/widgets/clearable_file_input.html +++ b/django/contrib/admin/templates/admin/widgets/clearable_file_input.html @@ -1,6 +1,6 @@ {% if widget.is_initial %}

{{ widget.initial_text }}: {{ widget.value }}{% if not widget.required %} - + {% endif %}
{{ widget.input_text }}:{% endif %} {% if widget.is_initial %}

{% endif %} diff --git a/django/forms/jinja2/django/forms/widgets/clearable_file_input.html b/django/forms/jinja2/django/forms/widgets/clearable_file_input.html index 9e76435216..93812837f0 100644 --- a/django/forms/jinja2/django/forms/widgets/clearable_file_input.html +++ b/django/forms/jinja2/django/forms/widgets/clearable_file_input.html @@ -1,5 +1,5 @@ {% if widget.is_initial %}{{ widget.initial_text }}: {{ widget.value }}{% if not widget.required %} - + {% endif %}
{{ widget.input_text }}:{% endif %} diff --git a/django/forms/templates/django/forms/widgets/clearable_file_input.html b/django/forms/templates/django/forms/widgets/clearable_file_input.html index 9e76435216..93812837f0 100644 --- a/django/forms/templates/django/forms/widgets/clearable_file_input.html +++ b/django/forms/templates/django/forms/widgets/clearable_file_input.html @@ -1,5 +1,5 @@ {% if widget.is_initial %}{{ widget.initial_text }}: {{ widget.value }}{% if not widget.required %} - + {% endif %}
{{ widget.input_text }}:{% endif %} diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py index 7241ea9554..b60d01e43f 100644 --- a/tests/admin_widgets/tests.py +++ b/tests/admin_widgets/tests.py @@ -487,6 +487,20 @@ class AdminFileWidgetTests(TestDataMixin, TestCase): }, ) + def test_render_disabled(self): + widget = widgets.AdminFileWidget(attrs={'disabled': True}) + self.assertHTMLEqual( + widget.render('test', self.album.cover_art), + '

Currently: albums\hybrid_theory.jpg ' + '' + '' + '
' + 'Change:

' % { + 'STORAGE_URL': default_storage.url(''), + }, + ) + def test_readonly_fields(self): """ File widgets should render as a link when they're marked "read only." diff --git a/tests/forms_tests/widget_tests/test_clearablefileinput.py b/tests/forms_tests/widget_tests/test_clearablefileinput.py index fabf71934f..dee44c4239 100644 --- a/tests/forms_tests/widget_tests/test_clearablefileinput.py +++ b/tests/forms_tests/widget_tests/test_clearablefileinput.py @@ -74,6 +74,21 @@ class ClearableFileInputTest(WidgetTest): """ self.check_html(self.widget, 'myfile', None, html='') + def test_render_disabled(self): + self.check_html( + self.widget, + 'myfile', + FakeFieldFile(), + attrs={'disabled': True}, + html=( + 'Currently: something' + '' + '
' + 'Change: ' + ), + ) + def test_render_as_subwidget(self): """A ClearableFileInput as a subwidget of MultiWidget.""" widget = MultiWidget(widgets=(self.widget,))