[1.6.x] Fixed #20999 - Allow overriding formfield class with choices, without subclass restrictions.

Refs #18162. Thanks claudep and mjtamlyn for review.

Backport of 7211741fc5 from master.
This commit is contained in:
Carl Meyer 2013-08-29 21:44:37 -06:00
parent 1d874ce0f9
commit 21a3efcf48
3 changed files with 22 additions and 16 deletions

View file

@ -68,14 +68,12 @@ class BasicFieldTests(test.TestCase):
self.assertEqual(m._meta.get_field('id').verbose_name, 'verbose pk')
def test_formclass_with_choices(self):
# regression for 18162
class CustomChoiceField(forms.TypedChoiceField):
pass
choices = [('a@b.cc', 'a@b.cc'), ('b@b.cc', 'b@b.cc')]
def test_choices_form_class(self):
"""Can supply a custom choices form class. Regression for #20999."""
choices = [('a', 'a')]
field = models.CharField(choices=choices)
klass = CustomChoiceField
self.assertIsInstance(field.formfield(form_class=klass), klass)
klass = forms.TypedMultipleChoiceField
self.assertIsInstance(field.formfield(choices_form_class=klass), klass)
class DecimalFieldTests(test.TestCase):