Найти - Пользователи
Полная версия: [django-mptt][bootstrap] Нарисовать дерево как таблицу
Начало » Django » [django-mptt][bootstrap] Нарисовать дерево как таблицу
1
nuklea
Решил заюзать 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>
Сходу не соображу, как это сделать. Есть идеи?
likin
Насколько, я понимаю это рекурсия…
Потому единственное решение которое я вижу, это создать свой тег.
Да тег не простой, а с генерацией шаблона одного уровня. Тогда у тебя пойдёт рекурсия типа шаблон - тег - шаблон - тег…..
Или просто реализуй рекурсивную функцию без участия шаблонизатора.
nuklea
Пока сделал так:

Вьюха
    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 %}
Планирую сделать фильтр nodes|tree_chunk:“3”
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB