在Django中冲突MPTTModel和TransMeta

时间:2012-09-27 08:30:10

标签: python django models mptt django-transmeta

我的django模型有问题。

这是我的模特:

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',]

我正在尝试在一个模型中合作两件事:TransMeta和MPTTModel。当我试图运行它时,我收到一个错误:

  

TypeError:调用元类库时出错       元类冲突:派生类的元类必须是(非严格)子类    其所有碱基的元类

我在谷歌找到了类似的解决方案:http://code.activestate.com/recipes/204197-solving-the-metaclass-conflict/并改变了我的代码:

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',]

classmaker的代码是http://code.activestate.com/recipes/204197-solving-the-metaclass-conflict/#block-0。但翻译不起作用。当我试图获得model.name时,我收到一个错误:

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

0 个答案:

没有答案