mirror of
https://github.com/django/django.git
synced 2025-08-18 17:50:58 +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
|
@ -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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue