title: Determining "last" element for each level in django-mptt
body: <p>I'm trying to generate a list akin to:</p>
  
  <pre><code>&lt;ul&gt;
      &lt;li&gt;Parent 1
          &lt;ul&gt;
              &lt;li&gt;Child 1&lt;/li&gt;
              &lt;li&gt;Child 2&lt;/li&gt;
              &lt;li class="last"&gt;Child 3&lt;/li&gt;
          &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Parent 2
          &lt;ul&gt;
              &lt;li&gt;Child 1&lt;/li&gt;
              &lt;li&gt;Child 2&lt;/li&gt;
              &lt;li class="last"&gt;Child 3&lt;/li&gt;
          &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li class="last"&gt;Parent 3
          &lt;ul&gt;
              &lt;li&gt;Child 1&lt;/li&gt;
              &lt;li&gt;Child 2&lt;/li&gt;
              &lt;li class="last"&gt;Child 3&lt;/li&gt;
          &lt;/ul&gt;
      &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>I originally just did:</p>
  
  <pre><code>&lt;ul&gt;
      {% recursetree mytree %}
      &lt;li class="{% if not node.get_next_sibling %}last{% endif %}"&gt;
          {{ node }}
          {% if not node.is_leaf_node %}
          &lt;ul&gt;
              {{ children }}
          &lt;/ul&gt;
          {% endif %}
      &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>However, the call to <code>node.get_next_sibling</code> results in an extra query for each item. Obviously, that's not ideal. So I tried using <code>tree_info</code> and <code>structure.closed_levels</code> to determine the last item:</p>
  
  <pre><code>{% for node,structure in mytree|tree_info %}
      {% if structure.new_level %}&lt;ul&gt;&lt;li&gt;{% else %}&lt;/li&gt;&lt;li&gt;{% endif %}
          &lt;li class="{% if structure.closed_levels|length &gt; 0 %}last{% endif %}"&gt;
              {{ node }}
      {% for level in structure.closed_levels %}&lt;/li&gt;&lt;/ul&gt;{% endfor %}
  {% endfor %}
  </code></pre>
  
  <p>This works great, except the last root level item does not get the "last" class, because its <code>structure.closed_levels</code> is always an empty list. (It really only works for child items).</p>
  
  <p>I'm sure I'm not the first to need to accomplish something similar, so I'm hoping someone here might have a solution already.</p>