neo4django multiple inheritance

做~自己de王妃 提交于 2019-12-11 12:07:27

问题


I was trying to create my model MyUser extending neo4django.auth.models.User, so I can use the underlying authentication system. The problem is I want create also a superclass from which derive many methods and attributes that are very common for my different kind of nodes.

I did this:

from neo4django.auth.models import User as AuthUser
class MyBaseModel(models.NodeModel):
    ....
    class Meta:
        abstract = True

class MyUser(MyBaseModel,AuthUser):
    ...

but any operation on the model gives me
ValueError: Multiple inheritance of NodeModels is not currently supported.

Suggestions, workarounds?
Since MyBaseModel is essentially a container of methods and attributes, maybe a decorator that adds that fields would be an elegant solution?

Thanks.


回答1:


You're right- Multiple inheritance with multiple NodeModel-inheriting bases won't work.

However, could MyBaseModel inherit from AuthUser? If not, you can also mixin a non-NodeModel class. So if MyBaseModel is just a container for methods, you can just do

class MyBaseModelMixin(object):
    ....

and then inherit from that

class MyUser(MyBaseModelMixin, AuthUser):
    ....


来源:https://stackoverflow.com/questions/18849973/neo4django-multiple-inheritance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!