我有以下模型类层次结构:
from django.db import models
class Entity(models.Model):
createTS = models.DateTimeField(auto_now=False, auto_now_add=True)
class Meta:
abstract = True
class Car(Entity):
pass
class Meta:
abstract = True
class Boat(Entity):
pass
class Amphibious(Boat,Car):
pass
不幸的是,这不适用于Django:
^{pr2}$即使我声明船是抽象的,也无济于事:
shop.Amphibious.createTS: (models.E006) The field 'createTS' clashes with the field 'createTS' from model 'shop.amphibious'.
有没有可能拥有一个具有多重继承和一个公共基类的模型类层次结构(模型。模型子类)声明一些字段?在
用这个看看是否有用。如果您试图在模型中包含时间戳,那么只需创建一个只包含时间戳的基本模型。在
我希望这有帮助。我看到你贴出这个问题已经5个月了。如果你已经找到了一个更好的解决方案,那么请与我们分享,将有助于我们学习。:)
相关问题 更多 >
编程相关推荐