March 2020
Intermediate to advanced
608 pages
17h 17m
English
Pass QuerySet of your hierarchical categories to the template and then use the {% recursetree %} template tag as follows:
# myproject/apps/categories/views.pyfrom django.views.generic import ListViewfrom .models import Categoryclass IdeaCategoryList(ListView): model = Category template_name = "categories/category_list.html" context_object_name = "categories"
{# categories/category_list.html #}{% extends "base.html" %}{% load mptt_tags %}{% block content %} <ul class="root"> {% recursetree categories %} <li> {{ node.title }} {% if not node.is_leaf_node %} <ul ...