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 ab35253a0d58..8b42f192f1a2 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/docs/releases/5.0.4.txt b/docs/releases/5.0.4.txt index d15c28d83df9..9b2fd6b17000 100644 --- a/docs/releases/5.0.4.txt +++ b/docs/releases/5.0.4.txt @@ -13,3 +13,7 @@ Bugfixes fields with expressions in ``db_default``. As a consequence, ``Model.full_clean()`` no longer validates for empty values in fields with ``db_default`` (:ticket:`35223`). + +* Fixed a regression in Django 5.0 where the ``AdminFileWidget`` could be + rendered with two ``id`` attributes on the "Clear" checkbox + (:ticket:`35273`). diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py index 50c26095ff21..76a47e486843 100644 --- a/tests/admin_widgets/tests.py +++ b/tests/admin_widgets/tests.py @@ -590,6 +590,19 @@ def test_render(self): '', ) + def test_render_with_attrs_id(self): + storage_url = default_storage.url("") + w = widgets.AdminFileWidget() + self.assertHTMLEqual( + w.render("test", self.album.cover_art, attrs={"id": "test_id"}), + f'

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

', + ) + def test_render_required(self): widget = widgets.AdminFileWidget() widget.is_required = True @@ -618,6 +631,20 @@ def test_render_disabled(self): }, ) + def test_render_checked(self): + storage_url = default_storage.url("") + widget = widgets.AdminFileWidget() + widget.checked = True + self.assertHTMLEqual( + widget.render("test", self.album.cover_art), + f'

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

', + ) + def test_readonly_fields(self): """ File widgets should render as a link when they're marked "read only."