【问题标题】:django-mptt tree rebuild errordjango-mptt 树重建错误
【发布时间】:2012-09-02 05:32:22
【问题描述】:

我用的是django-mptt版本(0,5,'+dev')

我的模型看起来像:

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 模型中更改 Meta:

class MPTTMeta:
        order_insertion_by = ['creation_time']

然后,我在 django shell 下重建树,然后是 THIS:

models.comment.tree.rebuild()

但是,它会抛出: AttributeError: type object 'Comment' has no attribute 'tree'

这有什么问题?如何在 django-mptt 中重建树?

谢谢!

【问题讨论】:

    标签: python django orm django-mptt mptt


    【解决方案1】:

    你试过了吗:

    Comment.objects.rebuild()
    

    因为rebuildfunction defined 上的TreeManager class

    在 SO 文章 you referenced 中,我假设他已将自定义管理器设置为 tree 属性。但你没有,因此在 objects 属性上。

    你认识Model Managers吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-11
      • 2011-07-01
      • 2011-11-05
      • 2015-08-08
      • 1970-01-01
      • 2012-09-04
      • 1970-01-01
      相关资源
      最近更新 更多