Django-mptt filter child from django template -
i have used django-mptt represent hierarchical data. data database table have used following code template.
{% load mptt_tags %} {% recursetree nodes %} {{ node.name }} {% endrecursetree %}
now want filter children id , need only 1 immediate child display in template.how can template?
level
property , get_previous_sibling can used achieve this:
{% load mptt_tags %} {% recursetree nodes %} {% if node.level == 0 %} {# first level #} {{ node.name }} {% elif not node.get_previous_sibling %} {# first child #} {{ node.name }} {% endif %} {{ children}} {% endrecursetree %}
please note get_previous_sibling
call trigger db query.
Comments
Post a Comment