mario199
mario199

Reputation: 406

Conflict MPTTModel and TransMeta in Django

I have problem with my django model.

This is my model:

class Item(MPTTModel):
    __metaclass__ = TransMeta

    name = models.CharField(max_length=250, verbose_name=u'Menu name', blank=True)
    parent = TreeForeignKey('self', null=True, blank=True, related_name='children')


    class Meta:
        translate = ('name',)

    class MPTTMeta:
        order_insertion_by = ['name',]

I am trying to cooperate two things in one model: TransMeta and MPTTModel. When I am trying to run it, I get a error:

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

I found a similar solution in google: http://code.activestate.com/recipes/204197-solving-the-metaclass-conflict/ and changed my code like this:

class Item(MPTTModel):

    __metaclass__ = classmaker(right_metas=(TransMeta,))


    name = models.CharField(max_length=250, verbose_name=u'Menu name', blank=True)
    parent = TreeForeignKey('self', null=True, blank=True, related_name='children')    


    class Meta:
        translate = ('name',)

    class MPTTMeta:
        order_insertion_by = ['name',]

Where classmaker is this code http://code.activestate.com/recipes/204197-solving-the-metaclass-conflict/#block-0. But translation doesn't work. When I am trying to get a model.name I am getting a error:

FieldDoesNotExist at /admin/menu/item/add/
Item has no field named 'name'

Upvotes: 2

Views: 322

Answers (0)

Related Questions