0

我创建了一个类,如 mptt 文档中所述

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'

为什么会这样?

4

1 回答 1

1

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

class RealtyAdminModelForm(forms.ModelForm):
    location = TreeNodeChoiceField(queryset=Locations.objects.all(),
                                   level_indicator=u'+--')
class Meta:
    model = Realty
于 2013-09-20T12:45:25.640 回答