menu submenu system

5 views
Skip to first unread message

Onno Timmerman

unread,
Oct 3, 2006, 3:18:19 AM10/3/06
to django...@googlegroups.com
I was wondering how you handle in Django a menu system with submenu's.

For example I give my client the ability to make there own menu's.
level1
level1
level2
level2
level3
level3
level2
level1
...
...
...


In the database I used table like "id, idSub, menu" and made a class in
PHP to process the data and order the submenu's in an array and then put
them where needed in a SELECT or UL list. I wonder how this is done with
Django.

Thanxs
PS. I'm still a bit confused about frameworks.

Rob Hudson

unread,
Oct 3, 2006, 3:51:49 PM10/3/06
to Django users
I did something like this recently on a project.

The way I approached it was to come up with a dataset that represented
the menu at the template level with the various bits I needed to know
in order to open another level, etc. Something like this:

menu = [
{'title': title, 'url': url, 'active': active, 'level': level},
...
}

In the view you'd query the database using the db api and gather the
data however you need to then build that data structure. Once built,
add the data structure to the template context so it's available to the
template. The template then uses the template API to iterate over the
menu list and output the menu.

I'm leaving out a lot of the details but that's a good summary, I think.

Reply all
Reply to author
Forward
0 new messages