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:
@@ -31,6 +31,10 @@ from django.utils.translation import gettext_lazy as _
|
||||
from .models import FoodManager, FoodQuerySet
|
||||
|
||||
|
||||
def get_choices():
|
||||
return [(i, str(i)) for i in range(3)]
|
||||
|
||||
|
||||
class DeconstructibleInstances:
|
||||
def deconstruct(self):
|
||||
return ("DeconstructibleInstances", [], {})
|
||||
@@ -493,6 +497,14 @@ class WriterTests(SimpleTestCase):
|
||||
"models.IntegerField(choices=[('Group', [(2, '2'), (1, '1')])])",
|
||||
)
|
||||
|
||||
def test_serialize_callable_choices(self):
|
||||
field = models.IntegerField(choices=get_choices)
|
||||
string = MigrationWriter.serialize(field)[0]
|
||||
self.assertEqual(
|
||||
string,
|
||||
"models.IntegerField(choices=migrations.test_writer.get_choices)",
|
||||
)
|
||||
|
||||
def test_serialize_nested_class(self):
|
||||
for nested_cls in [self.NestedEnum, self.NestedChoices]:
|
||||
cls_name = nested_cls.__name__
|
||||
|
||||
Reference in New Issue
Block a user