2010-04-15 20:41:08 +08:00
|
|
|
import datetime
|
2011-10-14 05:34:56 +08:00
|
|
|
|
2015-01-28 20:35:27 +08:00
|
|
|
from django.db import DJANGO_VERSION_PICKLE_KEY, models
|
2017-01-27 03:58:33 +08:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2010-03-27 23:54:31 +08:00
|
|
|
|
2011-10-14 05:34:56 +08:00
|
|
|
|
2013-03-29 20:32:21 +08:00
|
|
|
def standalone_number():
|
2010-04-22 00:34:33 +08:00
|
|
|
return 1
|
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2017-01-19 15:39:46 +08:00
|
|
|
class Numbers:
|
2010-04-22 00:34:33 +08:00
|
|
|
@staticmethod
|
2013-03-29 20:32:21 +08:00
|
|
|
def get_static_number():
|
2010-04-22 00:34:33 +08:00
|
|
|
return 2
|
2010-04-15 20:41:08 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2014-06-06 19:10:20 +08:00
|
|
|
class PreviousDjangoVersionQuerySet(models.QuerySet):
|
|
|
|
def __getstate__(self):
|
2017-01-21 21:13:44 +08:00
|
|
|
state = super().__getstate__()
|
2015-04-02 07:15:27 +08:00
|
|
|
state[DJANGO_VERSION_PICKLE_KEY] = '1.0'
|
2014-06-06 19:10:20 +08:00
|
|
|
return state
|
|
|
|
|
|
|
|
|
|
|
|
class MissingDjangoVersionQuerySet(models.QuerySet):
|
|
|
|
def __getstate__(self):
|
2017-01-21 21:13:44 +08:00
|
|
|
state = super().__getstate__()
|
2014-06-06 19:10:20 +08:00
|
|
|
del state[DJANGO_VERSION_PICKLE_KEY]
|
|
|
|
return state
|
|
|
|
|
|
|
|
|
2010-03-27 23:54:31 +08:00
|
|
|
class Group(models.Model):
|
|
|
|
name = models.CharField(_('name'), max_length=100)
|
2014-06-06 19:10:20 +08:00
|
|
|
objects = models.Manager()
|
|
|
|
previous_django_version_objects = PreviousDjangoVersionQuerySet.as_manager()
|
|
|
|
missing_django_version_objects = MissingDjangoVersionQuerySet.as_manager()
|
2010-03-27 23:54:31 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2010-03-27 23:54:31 +08:00
|
|
|
class Event(models.Model):
|
2014-12-24 21:58:32 +08:00
|
|
|
title = models.CharField(max_length=100)
|
2020-10-05 21:21:16 +08:00
|
|
|
group = models.ForeignKey(Group, models.CASCADE, limit_choices_to=models.Q())
|
2010-04-15 20:41:08 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2010-04-15 20:41:08 +08:00
|
|
|
class Happening(models.Model):
|
|
|
|
when = models.DateTimeField(blank=True, default=datetime.datetime.now)
|
2015-07-16 09:18:07 +08:00
|
|
|
name = models.CharField(blank=True, max_length=100, default="test")
|
2010-04-22 00:34:33 +08:00
|
|
|
number1 = models.IntegerField(blank=True, default=standalone_number)
|
2016-12-01 18:38:01 +08:00
|
|
|
number2 = models.IntegerField(blank=True, default=Numbers.get_static_number)
|
2017-10-19 09:43:53 +08:00
|
|
|
event = models.OneToOneField(Event, models.CASCADE, null=True)
|
2021-12-04 22:55:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
class BinaryFieldModel(models.Model):
|
2021-12-03 18:56:22 +08:00
|
|
|
data = models.BinaryField(null=True)
|
2013-05-21 17:57:24 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2017-01-19 15:39:46 +08:00
|
|
|
class Container:
|
2013-05-21 17:57:24 +08:00
|
|
|
# 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-03 05:34:05 +08:00
|
|
|
|
2013-05-21 17:57:24 +08:00
|
|
|
class M2MModel(models.Model):
|
2020-10-15 14:17:42 +08:00
|
|
|
added = models.DateField(default=datetime.date.today)
|
2013-05-21 17:57:24 +08:00
|
|
|
groups = models.ManyToManyField(Group)
|
2019-12-11 22:25:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
class AbstractEvent(Event):
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
ordering = ['title']
|
|
|
|
|
|
|
|
|
|
|
|
class MyEvent(AbstractEvent):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Edition(models.Model):
|
|
|
|
event = models.ForeignKey('MyEvent', on_delete=models.CASCADE)
|