How to display a nested list
I have a recursive table, of which I want to present the main elements and their sebelements
| id | name | parent | order |
|---|---|---|---|
| 1 | Menu A | 1 | |
| 2 | Menu B | 2 | |
| 3 | Menu a | 1 | 1 |
| 4 | Menu b | 2 | 1 |
| 5 | Menu C | 3 | |
| 6 | Menu D | 4 | |
| 7 | Menu a | 6 | 1 |
| 8 | Menu b | 6 | 2 |
And what I want to present respecting the order of the main Menu, and within each menu its submenu with the assigned order
View
menus = Menu.objects.values('id', 'name', 'icon', 'parent').filter(estado=1).order_by('order')
I'm using the regroup tag but it doesn't even group it by parent I think the change must be in values but I can't find the solution
TEMPLATE
{% regroup menus by parent as menu_list %}
{% for parent in menu_list %}
{{parent.grouper}}
{{parent.id}}, {{parent.name}}
{% for submenu in parent.list %}
{{submenu.id}}, {{submenu.name}}
{% endfor %}
{% endfor %}
Desired result
- Menu A
- Menu a
- Menu B
- Menu b
- Menu C
- Menu D
- Menu a
- Menu b