1

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.

tonjo
  • 1,394
  • 1
  • 14
  • 27

1 Answers1

0

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):
    ....
Matt Luongo
  • 14,371
  • 6
  • 53
  • 64
  • I want to use MyBaseModel also for other classes, not only users, so a Mixin would be better. MyBaseModel defines some common attributes, I want to be able to search (filter) on these too. Do I have to write a NodeModelManager? I kinda did that (named search), but when I try to use it: `User.search.filter(_where_prov="Verona") Traceback (most recent call last): ... File "/home/tonjo/venv/tuned/local/lib/python2.7/site-packages/neo4django/db/models/query.py", line 1222, in __init__ self._app_label = model._meta.app_label AttributeError: 'NoneType' object has no attribute '_meta'` – tonjo Sep 18 '13 at 14:08
  • And actually, MyUser inherits from MyBaseModel (mixin) only methods, no attributes :( Why is that? – tonjo Sep 18 '13 at 14:36
  • Hm, I'd really need more information to help with that. Maybe you could update the question with your newest efforts? – Matt Luongo Sep 18 '13 at 15:26
  • Having other problems, I [asked another question](http://stackoverflow.com/questions/18878290/neo4django-mixin-inheritance-problems) – tonjo Sep 18 '13 at 17:10