From fd75c8f2b7070774f6e90f408cb5cddf65b8734e Mon Sep 17 00:00:00 2001 From: Raphael Merx Date: Tue, 7 Mar 2017 12:22:45 +0900 Subject: [PATCH] =?UTF-8?q?Fixed=20#27905=20=E2=80=93=20Added=20RelatedFie?= =?UTF-8?q?ldWidgetWrapper.value=5Fomitted=5Ffrom=5Fdata().?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- django/contrib/admin/widgets.py | 3 +++ docs/releases/1.10.7.txt | 3 ++- tests/admin_widgets/tests.py | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py index 9d3c22540e..588bfb58e3 100644 --- a/django/contrib/admin/widgets.py +++ b/django/contrib/admin/widgets.py @@ -303,6 +303,9 @@ class RelatedFieldWidgetWrapper(forms.Widget): def value_from_datadict(self, data, files, name): return self.widget.value_from_datadict(data, files, name) + def value_omitted_from_data(self, data, files, name): + return self.widget.value_omitted_from_data(data, files, name) + def id_for_label(self, id_): return self.widget.id_for_label(id_) diff --git a/docs/releases/1.10.7.txt b/docs/releases/1.10.7.txt index dd5cf35fba..de9a511f07 100644 --- a/docs/releases/1.10.7.txt +++ b/docs/releases/1.10.7.txt @@ -9,4 +9,5 @@ Django 1.10.7 fixes several bugs in 1.10.6. Bugfixes ======== -* ... +* Made admin's ``RelatedFieldWidgetWrapper`` use the wrapped widget's + ``value_omitted_from_data()`` method (:ticket:`27905`). diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py index de59c26b22..b7814f966c 100644 --- a/tests/admin_widgets/tests.py +++ b/tests/admin_widgets/tests.py @@ -646,6 +646,15 @@ class RelatedFieldWidgetWrapperTests(SimpleTestCase): output = wrapper.render('name', 'value') self.assertIn('custom render output', output) + def test_widget_delegates_value_omitted_from_data(self): + class CustomWidget(forms.Select): + def value_omitted_from_data(self, data, files, name): + return False + rel = Album._meta.get_field('band').remote_field + widget = CustomWidget() + wrapper = widgets.RelatedFieldWidgetWrapper(widget, rel, widget_admin_site) + self.assertIs(wrapper.value_omitted_from_data({}, {}, 'band'), False) + @override_settings(ROOT_URLCONF='admin_widgets.urls') class AdminWidgetSeleniumTestCase(AdminSeleniumTestCase):