Retrieving Levels Optimally

26 views
Skip to first unread message

Eyrrkr

unread,
Apr 4, 2018, 11:35:02 PM4/4/18
to django-mptt-dev
All:

I'm trying to figure out how to optimally retrieve specific levels in a tree structure because I am building a navigation and although the root levels are the main headings, there are possibilities for other subheadings within those main headings (i.e. level 2 could be another bold subheading with level 3 as its children).  I am currently operating under the assumption that these depths could be flexible.

Below is what I currently have and I know it works although I think this is actually going in the opposite direction of what django-mptt is trying to achieve (cut down on database queries):

<ul class="root">
    {% recursetree object_list %}
        <li>
            {{ node.name }}
            {% for x in node.get_children %}
              <ul>
                {{ x.name }}
                {% if x.get_descendants %}
                  {% for y in x.get_descendants %}
                    <ul>
                      {{ y.name }}
                    </ul>
                  {% endfor %}
                {% endif %}
              </ul>
            {% endfor %}
        </li>
    {% endrecursetree %}
  </ul>

Thank you in advance for any help you can provide!

Reply all
Reply to author
Forward
0 new messages