Fixed #24561 -- Added support for callables on model fields' choices.

This commit is contained in:
Natalia 2023-08-31 09:09:30 -03:00
parent 5bfb3cbf49
commit 691f70c477
9 changed files with 101 additions and 31 deletions

View file

@ -391,26 +391,6 @@ class CharFieldTests(TestCase):
],
)
def test_choices_callable(self):
def get_choices():
return [(i, i) for i in range(3)]
class Model(models.Model):
field = models.CharField(max_length=10, choices=get_choices)
field = Model._meta.get_field("field")
self.assertEqual(
field.check(),
[
Error(
"'choices' must be a mapping (e.g. a dictionary) or an iterable "
"(e.g. a list or tuple).",
obj=field,
id="fields.E004",
),
],
)
def test_bad_db_index_value(self):
class Model(models.Model):
field = models.CharField(max_length=10, db_index="bad")