For example given the database model presented in the docs if I create
a more deeply nested structure and I render it all with recursetree
template tags as shown in the docs, I get a traversal that seems to be
incorrect (the only modification is that I added a small text to show
the name of the parent),
Note for example that the parent of A14 and A19 should be A09 yet are
shown at the level of A08. There are many other such examples. Am
misunderstanding what the output should be like?
And here is the code the generates the image above:
Genre.objects.all().delete()
root = Genre.objects.create(name="A00")
objs = [ root ]
for step in range(1, 26):
# distribute 25 children at random levels
name = "A%02d" % step
parent = random.choice(objs)
obj = Genre.objects.create(name=name, parent=parent)
objs.append(obj)
nodes = Genre.objects.all()
return html.template(request, "render.html", nodes=nodes)
and the template is:
{% load mptt_tags %}
<ul>
{% recursetree nodes %}
<li>
{{ node.name }} <span style="font-
size:smaller">({{node.parent.name}})</span>
{% if not node.is_leaf_node %}
<ul class="children">
{{ children }}
</ul>
{% endif %}
</li>
{% endrecursetree %}
</ul>
best,
Istvan
I have a same problem and couldn't find a solution. Please help.