mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #24561 -- Added support for callables on model fields' choices.
This commit is contained in:
@@ -318,3 +318,18 @@ class ValidationTests(SimpleTestCase):
|
||||
f.clean("A", None)
|
||||
with self.assertRaises(ValidationError):
|
||||
f.clean("3", None)
|
||||
|
||||
def test_callable_choices(self):
|
||||
def get_choices():
|
||||
return {i: str(i) for i in range(3)}
|
||||
|
||||
f = models.IntegerField(choices=get_choices)
|
||||
|
||||
for i in get_choices():
|
||||
with self.subTest(i=i):
|
||||
self.assertEqual(i, f.clean(i, None))
|
||||
|
||||
with self.assertRaises(ValidationError):
|
||||
f.clean("A", None)
|
||||
with self.assertRaises(ValidationError):
|
||||
f.clean("3", None)
|
||||
|
||||
Reference in New Issue
Block a user