[Fixed]-How do I rebuild my django-mptt tree?

20👍

AttributeError: Manager isn’t accessible via MyObj
instances

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

The model class here is MyObj. You are using a model instance my_rootnode

the correct usage is:

MyObj.tree.rebuild() (documentation link)

this will build MyObj tree.

👤manji

23👍

work for me:

MenuItem.objects.rebuild()

7👍

Recent MPTT version seem to require the following command. At least it worked for me today, although dash in front indicates that tree manager is private, and probably should not be accessed directly:

MyObj._tree_manager.rebuild()

4👍

manji is indeed right, you need to use the model class to call rebuild.

However, if you want to rebuild the tree only for a specific object and its descendants, you can use :

MyObj.tree.partial_rebuild(tree_id).

Leave a comment