I use two django packages - django-mptt (utilities for implementing Modified Preorder Tree Traversal) and django-hvad (model translation).
I have a model class MenuItem and I want to it extends TranslatableModel and MPTTModel, like this:
class MenuItem(TranslatableModel, MPTTModel):
but it causes metaclass conflict:
(TypeError: Error when calling the metaclass bases
metaclass conflict: the metaclass of a derived class
must be a (non-strict) subclass of the metaclasses of all its bases)
What is the solution this problem? I hope that I can use double inheritance.
You might want to do the following:
class CombinedMeta(TranslatableModel.__metaclass__, MPTTModel.__metaclass__):
pass
class MenuItem(TranslatableModel, MPTTModel):
__metaclass__=CombinedMeta
This should give you exactly what you want, without any error mesages.
Sorry for the late answer, but it i think it'll help for people who have same problem. When you subclass MPTTModel
and another class, make sure you put MPTTModel
first, like this:
class MenuItem(MPTTModel, TranslatableModel):
Generally the answer of @schacki would work. However, django-hvad overrides many other manager/queryset classes under the hood, which makes integrating with django-mptt/django-polymorphic and friends impossible at the moment.
Take a look at django-parler, which features a similar API and admin integration as django-hvad, but plays nice with other packages too. The table layout is identical, so you should be able to switch the packages easily.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With