summaryrefslogtreecommitdiff
path: root/tests/modeladmin/tests.py
diff options
context:
space:
mode:
authorJavier Matos Odut <iam@javiermatos.com>2018-10-31 15:16:17 +0100
committerTim Graham <timograham@gmail.com>2018-10-31 10:16:17 -0400
commit3d4d0a25b299a97314582156a0d63d939662d310 (patch)
treebbc4a1bf8c68866d917a32a9c970c2bfcdeb0aa5 /tests/modeladmin/tests.py
parentdf448bfd0259edb7df19c9c445ab4ee58624245d (diff)
Fixed #29901 -- Allowed overriding an autocomplete/raw_id_fields/radio_fields widget with ModelAdmin.get_formset().
Diffstat (limited to 'tests/modeladmin/tests.py')
-rw-r--r--tests/modeladmin/tests.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/modeladmin/tests.py b/tests/modeladmin/tests.py
index de216cbb11..6934bf2b3c 100644
--- a/tests/modeladmin/tests.py
+++ b/tests/modeladmin/tests.py
@@ -437,6 +437,28 @@ class ModelAdminTests(TestCase):
['main_band', 'day', 'transport', 'id', 'DELETE']
)
+ def test_raw_id_fields_widget_override(self):
+ """
+ The autocomplete_fields, raw_id_fields, and radio_fields widgets may
+ overridden by specifying a widget in get_formset().
+ """
+ class ConcertInline(TabularInline):
+ model = Concert
+ fk_name = 'main_band'
+ raw_id_fields = ('opening_band',)
+
+ def get_formset(self, request, obj=None, **kwargs):
+ kwargs['widgets'] = {'opening_band': Select}
+ return super().get_formset(request, obj, **kwargs)
+
+ class BandAdmin(ModelAdmin):
+ inlines = [ConcertInline]
+
+ ma = BandAdmin(Band, self.site)
+ band_widget = list(ma.get_formsets_with_inlines(request))[0][0]().forms[0].fields['opening_band'].widget
+ # Without the override this would be ForeignKeyRawIdWidget.
+ self.assertIsInstance(band_widget, Select)
+
def test_queryset_override(self):
# If the queryset of a ModelChoiceField in a custom form is overridden,
# RelatedFieldWidgetWrapper doesn't mess that up.