嗨,我一直在找遍,找不到答案。我只有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