diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py index 588bfb58e3..fd57436c46 100644 --- a/django/contrib/admin/widgets.py +++ b/django/contrib/admin/widgets.py @@ -347,13 +347,9 @@ class AdminURLFieldWidget(forms.URLInput): context = super().get_context(name, value, attrs) context['current_label'] = _('Currently:') context['change_label'] = _('Change:') - context['widget']['href'] = smart_urlquote(context['widget']['value']) + context['widget']['href'] = smart_urlquote(context['widget']['value']) if value else '' return context - def format_value(self, value): - value = super().format_value(value) - return force_text(value) - class AdminIntegerFieldWidget(forms.NumberInput): class_name = 'vIntegerField' diff --git a/django/forms/jinja2/django/forms/widgets/input.html b/django/forms/jinja2/django/forms/widgets/input.html index 7e70d1953f..abbdf6bd26 100644 --- a/django/forms/jinja2/django/forms/widgets/input.html +++ b/django/forms/jinja2/django/forms/widgets/input.html @@ -1 +1 @@ - + diff --git a/django/forms/templates/django/forms/widgets/input.html b/django/forms/templates/django/forms/widgets/input.html index 7e70d1953f..abbdf6bd26 100644 --- a/django/forms/templates/django/forms/widgets/input.html +++ b/django/forms/templates/django/forms/widgets/input.html @@ -1 +1 @@ - + diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 7db4c69aad..8b1069d040 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -180,8 +180,8 @@ class Widget(metaclass=MediaDefiningClass): """ Return a value as it should appear when rendered in a template. """ - if value is None: - value = '' + if value == '' or value is None: + return None if self.is_localized: return formats.localize_input(value) return force_text(value) diff --git a/tests/forms_tests/widget_tests/test_radioselect.py b/tests/forms_tests/widget_tests/test_radioselect.py index fea26cece1..58b2fc408e 100644 --- a/tests/forms_tests/widget_tests/test_radioselect.py +++ b/tests/forms_tests/widget_tests/test_radioselect.py @@ -7,8 +7,10 @@ class RadioSelectTest(WidgetTest): widget = RadioSelect def test_render(self): - self.check_html(self.widget(choices=self.beatles), 'beatle', 'J', html=( + choices = (('', '------'),) + self.beatles + self.check_html(self.widget(choices=choices), 'beatle', 'J', html=( """