From f8dd382a48d7dea8cda04a6674f305651e88c654 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Mon, 2 Jun 2014 07:05:38 -0400 Subject: [PATCH] [1.7.x] Revert "Fixed #19303 -- Fixed ModelAdmin.formfield_overrides on fields with choices" This reverts commit 9d1987d7679165ad3a7c2b713a8a488cc1421905. Backport of 5046c110cf from master --- django/contrib/admin/options.py | 4 ---- tests/admin_widgets/tests.py | 17 ----------------- 2 files changed, 21 deletions(-) diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 86da05a7fa..5fc0f26e60 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -152,7 +152,6 @@ class BaseModelAdmin(six.with_metaclass(RenameBaseModelAdminMethods)): return cls.checks_class().check(cls, model, **kwargs) def __init__(self): - self._orig_formfield_overrides = self.formfield_overrides overrides = FORMFIELD_FOR_DBFIELD_DEFAULTS.copy() overrides.update(self.formfield_overrides) self.formfield_overrides = overrides @@ -169,9 +168,6 @@ class BaseModelAdmin(six.with_metaclass(RenameBaseModelAdminMethods)): # If the field specifies choices, we don't need to look for special # admin widgets - we just need to use a select widget of some kind. if db_field.choices: - # see #19303 for an explanation of self._orig_formfield_overrides - if db_field.__class__ in self._orig_formfield_overrides: - kwargs = dict(self._orig_formfield_overrides[db_field.__class__], **kwargs) return self.formfield_for_choice_field(db_field, request, **kwargs) # ForeignKey or ManyToManyFields diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py index 56374d7534..119106e2a5 100644 --- a/tests/admin_widgets/tests.py +++ b/tests/admin_widgets/tests.py @@ -142,23 +142,6 @@ class AdminFormfieldForDBFieldTests(TestCase): self.assertEqual(f2.widget.attrs['maxlength'], '20') self.assertEqual(f2.widget.attrs['size'], '10') - def testFormfieldOverridesWidgetInstancesForFieldsWithChoices(self): - """ - Test that widget is actually overridden for fields with choices. - (#194303) - """ - class MemberAdmin(admin.ModelAdmin): - formfield_overrides = { - CharField: {'widget': forms.TextInput} - } - ma = MemberAdmin(models.Member, admin.site) - name_field = models.Member._meta.get_field('name') - gender_field = models.Member._meta.get_field('gender') - name = ma.formfield_for_dbfield(name_field, request=None) - gender = ma.formfield_for_dbfield(gender_field, request=None) - self.assertIsInstance(name.widget, forms.TextInput) - self.assertIsInstance(gender.widget, forms.TextInput) - def testFieldWithChoices(self): self.assertFormfield(models.Member, 'gender', forms.Select)