【发布时间】:2017-12-05 01:49:02
【问题描述】:
我使用django-mptt 库作为类别。我可以在模板中显示类别列表,但我想正确缩进它,以便用户可以知道哪个是主要类别,哪个是子类别等等。我尝试构建的方式是
{% recursetree nodes %}
<li class="node">
<a href="/category/{{ node.get_absolute_url }}"
class="{% if not node.is_leaf_node and not node.is_root_node and node.is_child_node %} child_parent {% elif node.is_leaf_node and not node.is_root_node %}leaf_node{% endif %}">
{{ node.name }}
{% if node.is_root_node %}
<span class="badge">{{ node.get_count_children }}</span>
{% endif %}
</a>
{% if not node.is_leaf_node %}
<ul class="children">
<li>{{ children }}</li>
</ul>
{% endif %}
</li>
{% endrecursetree %}
这产生了以下类别的设计
这里的 Dressing Table 是 Bed 和 Almirah 等卧室物品的子项,而不是 Bed 的子项。我该如何解决这个问题?我知道问题出在这里
<a href="/category/{{ node.get_absolute_url }}"
class="{% if not node.is_leaf_node and not node.is_root_node and node.is_child_node %} child_parent {% elif node.is_leaf_node and not node.is_root_node %}leaf_node{% endif %}">
但无法解决此问题
不是截图中的梳妆台
【问题讨论】:
-
你的意思是
Dressing Table是root节点吗? -
不,
dressing table是卧室物品的孩子(引用) -
那么渲染就已经正确了。
dressing table是卧室节点的子节点。您期望的结构是什么? -
不是我,但我猜它应该呈现为
Bed和Almirah,我再次引用图片下方的行。 -
好的。我得到了现在的情况。他需要确定叶子节点。但是该叶节点是根节点的第二级。所以他需要
Dressing Table成为cyan颜色。
标签: python django django-templates django-views django-mptt