为Django模型制作Mixins的正确方法

时间:2019-06-14 19:05:06

标签: django orm

我有以下mixins:

class AbandonableMixin(object):
    is_abandoned = models.BooleanField(
        default=False, verbose_name=_('Abandoned?'))


class ReadyMixin(object):
    is_ready = models.BooleanField(
        default=False, verbose_name=_('Ready?'))


class StoppableMixin(object):
    is_stopped = models.BooleanField(
        default=False, verbose_name=_('Stopped?'))

我想像普通的mixin一样在类中使用它们:

class MyObject(models.Model, AbandonableMixin, StoppableMixin): 
... 

class MySecondObject(models.Model, ReadyMixin, StoppableMixin):
...

这将导致以下错误:

TypeError: Cannot create a consistent method resolution
order (MRO) for bases Model, AbandonableMixin

我在做什么错?

0 个答案:

没有答案