I used django-mptt version (0,5,'+dev')
My model looks like:
class Comment(MPTTModel):
content = models.CharField(max_length = 300)
parent = TreeForeignKey('self', null=True, blank=True, related_name='child')
class MPTTMeta:
order_insertion_by = ['-creation_time']
Now, I change Meta in Comment model:
class MPTTMeta:
order_insertion_by = ['creation_time']
then, I rebuild the tree under the django shell followed by THIS:
models.comment.tree.rebuild()
However, it throws:
AttributeError: type object 'Comment' has no attribute 'tree'
What's wrong with that? How to rebuild the tree in django-mptt?
Thanks!
Have you tried:
Comment.objects.rebuild()
Because rebuild
is a function defined on the TreeManager class
In the SO article you referenced, I assume he had set a custom manager to the tree
attribute. But you haven't and thus is on the objects
attribute.
Are you acquainted with Model Managers?