Форум сайта python.su
Решил заюзать twitter bootstrap в проекте, потребовалось отрисовывать дерево примерное вот так:
<div class="row">
<div class="span4">
<h3><a href="#">{{ node.title }}</a></h3>
{% if not node.is_leaf_node %}
<ul class="children">{{ children }}</ul>
{% endif %}
</div>
<div class="span4">
<h3><a href="#">{{ node.title }}</a></h3>
{% if not node.is_leaf_node %}
<ul class="children">{{ children }}</ul>
{% endif %}
</div>
</div>
<div class="row">
<div class="span4">
<h3><a href="#">{{ node.title }}</a></h3>
{% if not node.is_leaf_node %}
<ul class="children">{{ children }}</ul>
{% endif %}
</div>
<div class="span4">
<h3><a href="#">{{ node.title }}</a></h3>
{% if not node.is_leaf_node %}
<ul class="children">{{ children }}</ul>
{% endif %}
</div>
</div>
Офлайн
Насколько, я понимаю это рекурсия…
Потому единственное решение которое я вижу, это создать свой тег.
Да тег не простой, а с генерацией шаблона одного уровня. Тогда у тебя пойдёт рекурсия типа шаблон - тег - шаблон - тег…..
Или просто реализуй рекурсивную функцию без участия шаблонизатора.
Офлайн
Пока сделал так:
Вьюха
root_node = get_object_or_404(Tree, classification=classification)
nodes = cache_tree_children(root_node.get_descendants())
chunks = map(None, *([iter(nodes)] * 3))
{% for chunk in chunks %}
<div class="row">
{% for node in chunk %}
{% if node %}
<div class="span4">
<h3><a href="#">{{ node.title }}</a></h3>
</div>
{% endif %}
{% endfor %}
</div>
{% endfor %}
Офлайн