Skip to content Skip to sidebar Skip to footer

How To Limit The Max Deep Of Recursetree In Django Mttp?

I'm using django-mttp. How can I limit the max depth of recursetree? Max=3 Model: class Comment(MPTTModel): '''评论表''' nid = models.AutoField(primary_key=True) ne

Solution 1:

Every instance of MPTTModel has a level attribute that can be used to limit the depth to recurse to. Just edit the recursive template to not show levels above a certain depth:

<ul>
  {% with max_depth=3 %}
    {% recursetree comments_list %}
      <li>
        {% if not node.is_leaf_node and node.level < max_depth %}  
          <ul>{{ children }}</ul>
        {% endif %}
      </li>
    {% endrecursetree %}
  {% endwith %}
</ul>

Post a Comment for "How To Limit The Max Deep Of Recursetree In Django Mttp?"