diff --git a/AUTHORS b/AUTHORS index 0c6994b5ea..a52ba34954 100644 --- a/AUTHORS +++ b/AUTHORS @@ -329,6 +329,7 @@ answer newbie questions, and generally made Django that much better: Helen Sherwood-Taylor Henrique Romano Henry Dang + Hidde Bultsma Himanshu Chauhan hipertracker@gmail.com Hiroki Kiyohara diff --git a/django/contrib/admin/templates/admin/widgets/related_widget_wrapper.html b/django/contrib/admin/templates/admin/widgets/related_widget_wrapper.html index 281d331443..7cdcb334c9 100644 --- a/django/contrib/admin/templates/admin/widgets/related_widget_wrapper.html +++ b/django/contrib/admin/templates/admin/widgets/related_widget_wrapper.html @@ -3,6 +3,7 @@ {{ rendered_widget }} {% block links %} {% spaceless %} + {% if not is_hidden %} {% if can_change_related %} {% endif %} + {% endif %} {% endspaceless %} {% endblock %} diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py index 9385104d59..81dbcaf236 100644 --- a/django/contrib/admin/widgets.py +++ b/django/contrib/admin/widgets.py @@ -285,6 +285,7 @@ class RelatedFieldWidgetWrapper(forms.Widget): ]) context = { 'rendered_widget': self.widget.render(name, value, attrs), + 'is_hidden': self.is_hidden, 'name': name, 'url_params': url_params, 'model': rel_opts.verbose_name, diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py index f7c2a7865c..623fa39bc1 100644 --- a/tests/admin_widgets/tests.py +++ b/tests/admin_widgets/tests.py @@ -687,6 +687,29 @@ class RelatedFieldWidgetWrapperTests(SimpleTestCase): wrapper = widgets.RelatedFieldWidgetWrapper(widget, rel, widget_admin_site) self.assertIs(wrapper.value_omitted_from_data({}, {}, 'band'), False) + def test_widget_is_hidden(self): + rel = Album._meta.get_field('band').remote_field + widget = forms.HiddenInput() + widget.choices = () + wrapper = widgets.RelatedFieldWidgetWrapper(widget, rel, widget_admin_site) + self.assertIs(wrapper.is_hidden, True) + context = wrapper.get_context('band', None, {}) + self.assertIs(context['is_hidden'], True) + output = wrapper.render('name', 'value') + # Related item links are hidden. + self.assertNotIn('