django-mptt tree rebuild error

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!

Answers


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?


Need Your Help

The best way of selecting div

jquery

I want to add to div#container a div inside another div and then get selector of the inner div. Which one is the better way to do this?

Controller for Web API, RESTful Web Methods. (With Angular)

c# angularjs rest web-api

I'm fairly new to c# and i'm completely stumped as to what I should be doing next to be processing inputs from a user inside of an input form I've created with Bootstrap and Html along with a angul...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.