0

I created a class as described in the 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

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'

Why is this so?

K DawG
  • 13,287
  • 9
  • 35
  • 66
Atterratio
  • 445
  • 2
  • 9
  • 25
  • 1
    Maybe as you added a __related_name = 'children'__ you have to use __Locations.children.all()__ instead of __Locations.tree.all()__ ? I'm not sure, but the __tree__ keyword could be a replacement for Django's default __fkname_set__ ? – Ricola3D Sep 20 '13 at 11:01
  • I second Locations.children.all() – dan-klasson Sep 20 '13 at 12:40
  • I just ran into this error upgrading an old project. At one time the 'tree' attribute worked, but has since been replaced with objects.all() – Wade Feb 02 '16 at 16:27

1 Answers1

1

I don't understand why in docs (http://django-mptt.github.io/django-mptt/forms.html) "tree", but the right is "objects":

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