Fixed #27850 -- Made RelatedFieldWidgetWrapper call render() of the wrapped widget.

This commit is contained in:
Collin Anderson 2017-02-20 08:48:03 -05:00 committed by Tim Graham
parent c743af82cf
commit fb7e0e01af
4 changed files with 27 additions and 17 deletions

View file

@ -596,6 +596,7 @@ class ManyToManyRawIdWidgetTest(TestCase):
)
@override_settings(ROOT_URLCONF='admin_widgets.urls')
class RelatedFieldWidgetWrapperTests(SimpleTestCase):
def test_no_can_add_related(self):
rel = Individual._meta.get_field('parent').remote_field
@ -630,6 +631,21 @@ class RelatedFieldWidgetWrapperTests(SimpleTestCase):
self.assertTrue(wrapper.can_change_related)
self.assertFalse(wrapper.can_delete_related)
def test_custom_widget_render(self):
class CustomWidget(forms.Select):
def render(self, *args, **kwargs):
return 'custom render output'
rel = Album._meta.get_field('band').remote_field
widget = CustomWidget()
wrapper = widgets.RelatedFieldWidgetWrapper(
widget, rel, widget_admin_site,
can_add_related=True,
can_change_related=True,
can_delete_related=True,
)
output = wrapper.render('name', 'value')
self.assertIn('custom render output', output)
@override_settings(ROOT_URLCONF='admin_widgets.urls')
class AdminWidgetSeleniumTestCase(AdminSeleniumTestCase):