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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -