我创建了一个类,如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'
为什么会这样?
答案 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