2012-09-08 32 views
3

我用Django的MPTT版本(0,5, '+開發')Django的MPTT樹重建錯誤

我的模型看起來像:

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'] 

現在,我改元在Comment模型:

class MPTTMeta: 
     order_insertion_by = ['creation_time'] 

然後,我重建Django的殼跟着樹下的THIS

models.comment.tree.rebuild()

然而,它拋出: AttributeError: type object 'Comment' has no attribute 'tree'

這有什麼錯呢?如何重建django-mptt中的樹?

謝謝!

回答

4

你試過:

Comment.objects.rebuild() 

因爲rebuild是在TreeManager class

在SO文章you referenced一個function defined,我認爲他已經設置自定義的經理到tree屬性。但是你沒有,因此屬於objects屬性。

你跟Model Managers熟嗎?

+1

謝謝安德烈。它的工作原理:) – hushwings

+0

不客氣。 –