django - display menu and multilevel submenu -
i need display menu list , multilevel submenu list, ex:
menu1 --menu2 ----menu3 --menu4 menu5 --menu6
here code:
model:
class menu(models.model): status = models.booleanfield(default=false) name = models.charfield(max_length=45) parent_id = models.foreignkey(u'self', null=true, blank=true, related_name=u'parent_menu')
view:
menu = {} map(lambda c: menu.setdefault(c.parent_id, []).append(c), \ menu.objects.filter(status=true).select_related('parent_menu')) context['menu'] = menu homecoming context
template:
{% mymenu, mysubmenu in menu.items %} {{ category.name }} {% mysubmenu in mysubmenu %} {{ mysubmenu }} {% endfor %} {% endfor %}
the actual problem is, don´t right list of more 1 level. display like:
menu1 --menu2 menu2 --menu3 --menu4 menu5 --menu6
django django-templates django-views
No comments:
Post a Comment