Reputation: 41
I'm having problem with Django MPTT my models is
class Catalog(MPTTModel):
name = models.CharField(verbose_name='name',max_length=256,blank=True )
name_slug = models.CharField(verbose_name='Name_slug',max_length=250,blank=True)
parent = TreeForeignKey('self',null=True,blank=True,related_name='children')
class MPTTMeta:
order_insertion_by = ['name']
def __unicode__(self):
return u"%s %s %s " %(self.name,self.name_slug,self.parent)
def __str__(self):
return u"%s %s %s " %(self.name,self.name_slug,self.parent
def get_absolute_url(self):
return reverse("catalog",kwargs={"slug":self.name_slug})
Now, I use MPTT in base.html, like this:
<ul class="root">
{% recursetree nodes %}
<li>
<a href="{{ node.get_absolute_url }}">{{ node.name }}</a>
{% if not node.is_leaf_node %}
<ul class="children">
<a href="{{ children.get_absolute_url }}">{{ children }}</a>
</ul>
{% endif %}
</li>
{% endrecursetree %}
However when I go to my page with mptt tree I can see:
VariableDoesNotExist at /list/
Failed lookup for key [nodes] in u"[{'False': False, 'None': None, 'True': True}, {}, {}, {'places': <QuerySet [<Place: \u041b\u044c\u0432\u0456\u0432 lvv \u0441\u0456\u0456\u0441\u0441\u0456\u0441\u0456\u0456\u0441 list.Catalog.None >, <Place: \u0421\u043a\u0430\u043b\u0430\u0442 skalat \u0421\u043a\u0430\u043b\u0430\u0442 list.Catalog.None >]>}]"
Can you tell me where is my problem?
Upvotes: 1
Views: 1809
Reputation: 2249
Don't forget that with the example {% recursetree nodes %}
, nodes
is actually the name of your categories template variable.
So if your views.py
sends the categories object to the template as categories
, then you need to use {% recursetree categories %}
instead.
Within the recursetree
block, node
is hardcoded to the individual node of the tree and children
is hardcoded to the children of that node, but nodes
is just an example template variable name.
Upvotes: 6