嗨,我一直在找遍,找不到答案。我只有3个月的使用python/django的经验,所以请原谅我的虚拟问题! 我使用django mptt来显示简单的嵌套设置导航。显示子节点取决于选定的父母
<ul class="root">
{% recursetree nodes %}
<li>
{{ node.name }}
{% if not node.is_leaf_node %}
<ul class="children">
{{ children }}
</ul>
{% endif %}
</li>
{% endrecursetree %}
这工作得很好 - 但我想只显示所选类别(基于蛞蝓),而不是所有的人的孩子。 任何想法???
我终于做到了这样:
{% recursetree nodes %}
<li>
<a href='/{{ node.get_absolute_url}}'>{{ node.name }}</a>
</li>
{% if not node.is_leaf.node %}
{% for c in child %}
{% if c in node.get_children %}
{% if forloop.first %}
<ul class="children">
{{ children }}
</ul>
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% endrecursetree %}
的意见
category = get_object_or_404(Category, slug=slug)
child = category.get_children()
if not child :
child = category.get_siblings()
,但它是一个黑客。有没有人有更好的主意?
我终于做了这个像这样 – zzart 2011-05-31 19:01:16