简体   繁体   English

Django-mptt形式“属性错误”

[英]Django-mptt form “Attribute error”

I created a class as described in the mptt docs 我按照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

I'm doing a form as written in the manual 我正在按照手册中的内容填写表格

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

But django gives the following error: type object 'Locations' has no attribute 'tree' 但是django提供了以下错误: type object 'Locations' has no attribute 'tree'

Why is this so? 为什么会这样呢?

I don't understand why in docs ( http://django-mptt.github.io/django-mptt/forms.html ) "tree", but the right is "objects": 我不明白为什么在文档( 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM