show children nodes depending on selected parent

前端 未结 3 473
-上瘾入骨i
-上瘾入骨i 2021-02-10 16:51

Hi i\'ve been looking all over and can\'t find the answer to this. I have only 3 months experience in using python/django so excuse my dummy quesion! Im using django mptt to di

相关标签:
3条回答
  • 2021-02-10 17:25

    You can try this:

    {% recursetree nodes %}
        #check if the node is a child node
        {% if node.is_child_node %}
            <a href="{{ node.get_absolute_url }}" >{{ node.name }}</a>
        {% endif %}
    
        #check if a root node is the current category
        {% if node.is_root_node and node.name == category.name %}
            {{ children }}
        {% endif %}
    
    {% endrecursetree %}
    
    0 讨论(0)
  • 2021-02-10 17:42

    You need to send down some information about what node you're in, and then it's a simple if statement.

    Regarding how to send down the node information universally, there are a couple ways to do this in Django, and none of them are perfect. My preferred method is context processors: http://docs.djangoproject.com/en/1.3/ref/templates/api/#writing-your-own-context-processors

    0 讨论(0)
  • 2021-02-10 17:44
    {% recursetree nodes %}
      <li>
          <a href="/category/{{ node.get_absolute_url }}">{{ node.name }}</a>                           
           {% if node.name == category.name %}
             <ul>
                {{ children }}
             </ul>
           {% endif %}
      <li>
    {% endrecursetree %}
    
    0 讨论(0)
提交回复
热议问题