0
我想升级到Django 1.7并从南切换到Django的集成迁移。我遇到了模型问题。我有一个基类:Django 1.7迁移与抽象基类
class CalendarDisplay():
"""
Inherit from this class to express that a class type is able to be displayed in the calendar.
Calling get_visual_end() will artificially lengthen the end time so the event is large enough to
be visible and clickable.
"""
start = None
end = None
def __init__(self):
pass
def get_visual_end(self):
if self.end is None:
return max(self.start + timedelta(minutes=15), timezone.now())
else:
return max(self.start + timedelta(minutes=15), self.end)
class Meta:
abstract = True
这里是继承了它的类的实例:
class Reservation(models.Model, CalendarDisplay):
user = models.ForeignKey(User)
start = models.DateTimeField('start')
end = models.DateTimeField('end')
...
现在我尝试迁移我的应用程序,但得到的错误如下:python manage.py makemigrations
Migrations for 'Example':
0001_initial.py:
- Create model Account
...
ValueError: Cannot serialize: <class Example.models.CalendarDisplay at 0x2f01ce8>
There are some values Django cannot serialize into migration files.
我的解决方案有哪些选择? Django 1.7迁移可以处理抽象基类吗?我宁愿保留我的抽象基类并继承它,但是,将必要的函数复制并粘贴到适当的类中是最后的手段。