2

我的 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:调用元类基类时出错元类冲突:派生类的元类必须是其所有基类的元类的(非严格)子类

我在 google 中找到了类似的解决方案: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'
4

0 回答 0