在Django抽象模型中使用多重继承可以吗? [英] Is it OK to use multiple inheritance with Django abstract models?

查看:79
本文介绍了在Django抽象模型中使用多重继承可以吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个不同的抽象模型基类。 。 。我想在多重继承中使用它们,就像Mixins。

I have three different abstract model base classes . . . I'd like to use them in multiple inheritance, sort of like Mixins. Any problems with this?

例如,

class TaggableBase(models.Model):

. . .

    class Meta:
        abstract = True

class TimeStampedBase(models.Model):

. . .

    class Meta:
        abstract = True

class OrganizationalBase(models.Model):

. . .

    class Meta:
        abstract = True

class MyTimeStampedTaggableOrganizationalModel(OrganizationalBase, TimeStampedBase, TaggableBase):

. . . 


推荐答案

听起来像您想要做的事情, mixins 确实是最合适的。一个简单的Google搜索将找到许多有关在python中实现混合功能的文章,例如。我不确定多重继承是实现此目标的最佳方法,因此您可能想探索所有其他选项。你还想什么?

Sounds like for what you're trying to do, mixins really are the best fit. A simple google search will find lots of articles on implementing mixins in python, such as this one. I'm not sure multiple inheritance is the best way to go about doing it, so you might want to explore all the other options. What else have you thought about?

这篇关于在Django抽象模型中使用多重继承可以吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆