0

In View:

context['categories'] =  = models.Category.objects.all().get_cached_trees()

In template:

{% load mptt_tags %}
<ul>
    {% recursetree categories %}
        <li>
            {{ node.name }}
            {% if not node.is_leaf_node %}
                <ul class="children">
                    {{ children }}
                </ul>
            {% endif %}
        </li>
    {% endrecursetree %}
</ul>

As a result, it renders only first level of queryset. If remove get_cached_trees it renders all tree. How to render all tree with get_cached_trees?

dreamstack
  • 13
  • 3

1 Answers1

0

You don't actually need to call get_cached_trees() in this situation because recursetree already does the caching for you.

From the documentation:

Iterates over the nodes in the tree, and renders the contained block for each node.
This tag will recursively render children into the template variable {{ children }}.
Only one database query is required (children are cached for the whole tree)
jpm
  • 405
  • 5
  • 7