本文介绍了如何重建我的django-mptt树?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用django-mptt 0.4.2,并希望重建树。
I'm using django-mptt 0.4.2, and want to rebuild a tree.
树管理器有一个方法rebuild(),我尝试访问像这样:
The tree manager has a method rebuild() which I try to access like this:
>>> my_rootnode = MyObj.objects.get(id=12)
>>> my_rootnode.tree.rebuild()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/django/db/models/manager.py", line 211, in __get__
raise AttributeError("Manager isn't accessible via %s instances" % type.__name__)
AttributeError: Manager isn't accessible via MyObj instances
我显然这样做错了。如何访问重建方法?
I'm obviously doing this wrong. How should I access the rebuild method?
推荐答案
mptt Manager
继承来自 django.db.models.Manager
,无法通过模型实例访问,但只能通过模型类访问。更多信息:
mptt Manager
inherits from django.db.models.Manager
which can not be accessed via model instances but only via model classes. More infos:Retrieving objects
这里的模型类是 MyObj
。您正在使用模型实例 my_rootnode
The model class here is MyObj
. You are using a model instance my_rootnode
正确的用法是:
MyObj.tree.rebuild()
这将构建MyObj树。
this will build MyObj tree.
这篇关于如何重建我的django-mptt树?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!