title: How to retrieve the children in Django
body: <p>I have a model Category like so :</p>
  
  <pre><code>class Category(TimeStampedModel):
      category_parent = models.ForeignKey('self', blank=True, null=True)
      name = models.CharField(max_length = 200)
      slug = models.SlugField(unique=True)
      def __str__(self):
          return self.name
  </code></pre>
  
  <p>What I want is to display all the categories that do not have parents at first, and then, in nested lists, their respective children : for example :</p>
  
  <pre><code>Flowers
    Lilac
    Rose
  Trees
    Maple
  </code></pre>
  
  <p>So what I have tried is that :</p>
  
  <pre><code>def get_categories(request):
      categories = Category.objects.filter(category_parent=None)
      return {'categories' : categories}
  </code></pre>
  
  <p>But when I try to display the children of each category, none appears, following my example, I only get Flowers and Trees..</p>
  
  <pre><code>&lt;ul class="nav-list"&gt;
       {% for category in categories %}
           &lt;li class="nav-item"&gt;&lt;a class="nav-link" href="#"&gt;{{ category.name }}&lt;/a&gt;
           {% if category.categories %}
                &lt;ul class="nav-submenu"&gt;
                  {% for subcategory in category.categories %}
                  &lt;li class="nav-submenu-item"&gt;&lt;a href="#"&gt;{{ subcategory.name }}&lt;/a&gt;&lt;/li&gt;
                  {% endfor %}
                &lt;/ul&gt;
           {% endif %}
           &lt;/li&gt;
       {% endfor %}
   &lt;/ul&gt;
  </code></pre>
  
  <p>How can I get the children too ?</p>