mirror of
https://github.com/django/django.git
synced 2025-09-27 04:29:17 +00:00
[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:
parent
1d874ce0f9
commit
21a3efcf48
3 changed files with 22 additions and 16 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue