mirror of
https://github.com/django/django.git
synced 2025-11-24 21:00:12 +00:00
Fixed #24561 -- Added support for callables on model fields' choices.
This commit is contained in:
parent
5bfb3cbf49
commit
691f70c477
9 changed files with 101 additions and 31 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue