Commit 04e69598 authored by Tim Graham's avatar Tim Graham
Browse files

Refs #24919 -- Made test models serializable for migrations.

parent 8a5eadd1
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -422,10 +422,12 @@ class Category(models.Model):
        return '%s:o%s' % (self.id, self.order)


def link_posted_default():
    return datetime.date.today() - datetime.timedelta(days=7)


class Link(models.Model):
    posted = models.DateField(
        default=lambda: datetime.date.today() - datetime.timedelta(days=7)
    )
    posted = models.DateField(default=link_posted_default)
    url = models.URLField()
    post = models.ForeignKey("Post")

+2 −1
Original line number Diff line number Diff line
@@ -12,7 +12,8 @@ class R(models.Model):
        return "%s" % self.pk


get_default_r = lambda: R.objects.get_or_create(is_default=True)[0]
def get_default_r():
    return R.objects.get_or_create(is_default=True)[0]


class S(models.Model):
+2 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import warnings

from django.db import models
from django.utils import six
from django.utils.deconstruct import deconstructible
from django.utils.deprecation import RemovedInDjango110Warning
from django.utils.encoding import force_text, python_2_unicode_compatible

@@ -16,6 +17,7 @@ warnings.filterwarnings(
)


@deconstructible
@python_2_unicode_compatible
class Small(object):
    """
+54 −14
Original line number Diff line number Diff line
@@ -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):
+5 −13
Original line number Diff line number Diff line
import datetime

from django.db import DJANGO_VERSION_PICKLE_KEY, models
from django.utils import six
from django.utils.translation import ugettext_lazy as _


@@ -13,15 +14,6 @@ class Numbers(object):
    def get_static_number():
        return 2

    @classmethod
    def get_class_number(cls):
        return 3

    def get_member_number(self):
        return 4

nn = Numbers()


class PreviousDjangoVersionQuerySet(models.QuerySet):
    def __getstate__(self):
@@ -51,11 +43,11 @@ class Event(models.Model):

class Happening(models.Model):
    when = models.DateTimeField(blank=True, default=datetime.datetime.now)
    name = models.CharField(blank=True, max_length=100, default=lambda: "test")
    name = models.CharField(blank=True, max_length=100, default="test")
    number1 = models.IntegerField(blank=True, default=standalone_number)
    if six.PY3:
        # default serializable on Python 3 only
        number2 = models.IntegerField(blank=True, default=Numbers.get_static_number)
    number3 = models.IntegerField(blank=True, default=Numbers.get_class_number)
    number4 = models.IntegerField(blank=True, default=nn.get_member_number)


class Container(object):
Loading