diff options
author | Tim Graham <timograham@gmail.com> | 2015-07-15 21:18:07 -0400 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2015-07-21 09:19:40 -0400 |
commit | 04e69598de75550a9227bfac353ff5606b6cbe43 (patch) | |
tree | 8048ec5726196ce1cabfa4f80eed72ffda45350e /tests/forms_tests | |
parent | 8a5eadd140a5f06d24e1c5bc0c444ce11be0769a (diff) | |
download | django-04e69598de75550a9227bfac353ff5606b6cbe43.tar.gz |
Refs #24919 -- Made test models serializable for migrations.
Diffstat (limited to 'tests/forms_tests')
-rw-r--r-- | tests/forms_tests/models.py | 68 |
1 files changed, 54 insertions, 14 deletions
diff --git a/tests/forms_tests/models.py b/tests/forms_tests/models.py index 830927aeba..7eb4792213 100644 --- a/tests/forms_tests/models.py +++ b/tests/forms_tests/models.py @@ -10,7 +10,10 @@ from django.db import models from django.utils.encoding import python_2_unicode_compatible callable_default_counter = itertools.count() -callable_default = lambda: next(callable_default_counter) + + +def callable_default(): + return next(callable_default_counter) temp_storage = FileSystemStorage(location=tempfile.mkdtemp()) @@ -68,25 +71,62 @@ class ChoiceOptionModel(models.Model): return 'ChoiceOption %d' % self.pk +def choice_default(): + return ChoiceOptionModel.objects.get_or_create(name='default')[0] + + +def choice_default_list(): + return [choice_default()] + + +def int_default(): + return 1 + + +def int_list_default(): + return [1] + + class ChoiceFieldModel(models.Model): """Model with ForeignKey to another model, for testing ModelForm generation with ModelChoiceField.""" - choice = models.ForeignKey(ChoiceOptionModel, blank=False, - default=lambda: ChoiceOptionModel.objects.get(name='default')) - choice_int = models.ForeignKey(ChoiceOptionModel, blank=False, related_name='choice_int', - default=lambda: 1) - - multi_choice = models.ManyToManyField(ChoiceOptionModel, blank=False, related_name='multi_choice', - default=lambda: ChoiceOptionModel.objects.filter(name='default')) - multi_choice_int = models.ManyToManyField(ChoiceOptionModel, blank=False, related_name='multi_choice_int', - default=lambda: [1]) + choice = models.ForeignKey( + ChoiceOptionModel, + blank=False, + default=choice_default, + ) + choice_int = models.ForeignKey( + ChoiceOptionModel, + blank=False, + related_name='choice_int', + default=int_default, + ) + multi_choice = models.ManyToManyField( + ChoiceOptionModel, + blank=False, + related_name='multi_choice', + default=choice_default_list, + ) + multi_choice_int = models.ManyToManyField( + ChoiceOptionModel, + blank=False, + related_name='multi_choice_int', + default=int_list_default, + ) class OptionalMultiChoiceModel(models.Model): - multi_choice = models.ManyToManyField(ChoiceOptionModel, blank=False, related_name='not_relevant', - default=lambda: ChoiceOptionModel.objects.filter(name='default')) - multi_choice_optional = models.ManyToManyField(ChoiceOptionModel, blank=True, - related_name='not_relevant2') + multi_choice = models.ManyToManyField( + ChoiceOptionModel, + blank=False, + related_name='not_relevant', + default=choice_default, + ) + multi_choice_optional = models.ManyToManyField( + ChoiceOptionModel, + blank=True, + related_name='not_relevant2', + ) class FileModel(models.Model): |