tree traversal problems

31 views
Skip to first unread message

Istvan Albert

unread,
Dec 7, 2011, 2:53:50 PM12/7/11
to django-mptt-dev
I am having some troubles with nested hierarchies, the node traversals
seem to be incorrect, I am not sure wether I am using it right and I
would like some advice.

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),

http://imgur.com/r4SOT

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>

Istvan Albert

unread,
Dec 7, 2011, 2:55:45 PM12/7/11
to django-mptt-dev

whoops, I've hit enter too soon and forgot to say "Hello Everyone" ...
and ... "thanks for all input!"

best,

Istvan

kada

unread,
Dec 11, 2011, 11:12:02 PM12/11/11
to django-mptt-dev
Hello

I have a same problem and couldn't find a solution. Please help.

Reply all
Reply to author
Forward
0 new messages