Django-mptt形式“属性错误”

时间:2013-09-20 10:52:06

标签: python django django-forms django-mptt

我创建了一个类,如mptt docs

中所述
class Locations(MPTTModel):
    title = models.CharField(max_length=100)
    parent = TreeForeignKey('self', null=True, blank=True, related_name='children')

    def __unicode__(self):
        return self.title

我正在做一本手册

中写的表格
class RealtyAdminModelForm(forms.ModelForm):
    location = TreeNodeChoiceField(queryset=Locations.tree.all(),
                                   level_indicator=u'+--')
class Meta:
    model = Realty

但是django会出现以下错误: type object 'Locations' has no attribute 'tree'

为什么会这样?

1 个答案:

答案 0 :(得分:1)

我不明白为什么在docs(http://django-mptt.github.io/django-mptt/forms.html)“tree”中,但右边是“对象”:

class RealtyAdminModelForm(forms.ModelForm):
    location = TreeNodeChoiceField(queryset=Locations.objects.all(),
                                   level_indicator=u'+--')
class Meta:
    model = Realty