2010-04-15 12:41:08 +00:00
|
|
|
import datetime
|
2011-10-13 21:34:56 +00:00
|
|
|
|
2015-01-28 12:35:27 +00:00
|
|
|
from django.db import DJANGO_VERSION_PICKLE_KEY, models
|
2010-03-27 15:54:31 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
2011-10-13 21:34:56 +00:00
|
|
|
|
2013-03-29 12:32:21 +00:00
|
|
|
def standalone_number():
|
2010-04-21 16:34:33 +00:00
|
|
|
return 1
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2010-04-15 12:41:08 +00:00
|
|
|
class Numbers(object):
|
2010-04-21 16:34:33 +00:00
|
|
|
@staticmethod
|
2013-03-29 12:32:21 +00:00
|
|
|
def get_static_number():
|
2010-04-21 16:34:33 +00:00
|
|
|
return 2
|
2010-04-15 12:41:08 +00:00
|
|
|
|
|
|
|
@classmethod
|
2013-03-29 12:32:21 +00:00
|
|
|
def get_class_number(cls):
|
2010-04-21 16:34:33 +00:00
|
|
|
return 3
|
|
|
|
|
|
|
|
def get_member_number(self):
|
|
|
|
return 4
|
|
|
|
|
|
|
|
nn = Numbers()
|
2010-04-15 12:41:08 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2014-06-06 11:10:20 +00:00
|
|
|
class PreviousDjangoVersionQuerySet(models.QuerySet):
|
|
|
|
def __getstate__(self):
|
|
|
|
state = super(PreviousDjangoVersionQuerySet, self).__getstate__()
|
2015-04-01 23:15:27 +00:00
|
|
|
state[DJANGO_VERSION_PICKLE_KEY] = '1.0'
|
2014-06-06 11:10:20 +00:00
|
|
|
return state
|
|
|
|
|
|
|
|
|
|
|
|
class MissingDjangoVersionQuerySet(models.QuerySet):
|
|
|
|
def __getstate__(self):
|
|
|
|
state = super(MissingDjangoVersionQuerySet, self).__getstate__()
|
|
|
|
del state[DJANGO_VERSION_PICKLE_KEY]
|
|
|
|
return state
|
|
|
|
|
|
|
|
|
2010-03-27 15:54:31 +00:00
|
|
|
class Group(models.Model):
|
|
|
|
name = models.CharField(_('name'), max_length=100)
|
2014-06-06 11:10:20 +00:00
|
|
|
objects = models.Manager()
|
|
|
|
previous_django_version_objects = PreviousDjangoVersionQuerySet.as_manager()
|
|
|
|
missing_django_version_objects = MissingDjangoVersionQuerySet.as_manager()
|
2010-03-27 15:54:31 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2010-03-27 15:54:31 +00:00
|
|
|
class Event(models.Model):
|
2014-12-24 13:58:32 +00:00
|
|
|
title = models.CharField(max_length=100)
|
2010-03-27 15:54:31 +00:00
|
|
|
group = models.ForeignKey(Group)
|
2010-04-15 12:41:08 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2010-04-15 12:41:08 +00:00
|
|
|
class Happening(models.Model):
|
|
|
|
when = models.DateTimeField(blank=True, default=datetime.datetime.now)
|
2013-10-26 19:15:03 +00:00
|
|
|
name = models.CharField(blank=True, max_length=100, default=lambda: "test")
|
2010-04-21 16:34:33 +00:00
|
|
|
number1 = models.IntegerField(blank=True, default=standalone_number)
|
|
|
|
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)
|
2013-05-21 09:57:24 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2013-05-21 09:57:24 +00:00
|
|
|
class Container(object):
|
|
|
|
# To test pickling we need a class that isn't defined on module, but
|
|
|
|
# is still available from app-cache. So, the Container class moves
|
|
|
|
# SomeModel outside of module level
|
|
|
|
class SomeModel(models.Model):
|
|
|
|
somefield = models.IntegerField()
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2013-05-21 09:57:24 +00:00
|
|
|
class M2MModel(models.Model):
|
|
|
|
groups = models.ManyToManyField(Group)
|