implementing django-treemenus

108 views
Skip to first unread message

gowtham

unread,
Apr 18, 2012, 2:15:19 PM4/18/12
to django-...@googlegroups.com
Hi Everyone,
Another newbie question to the group.

For the tiny Django application I created for past few weeks, we decided to implement a menu with tree structure. I found django-treemenus application started to implement it (I am still open to other suggestions). I could not quite get everything correct. I have completed following steps and dont know where to go from there...

1) Installed the code
2) added 'treemenus' to installed apps & syncdb created needed tables
3) url(r'^admin/treemenus/', include('treemenus.admin_urls')), added to URLs file (before admin)
4) using admin, added a menu with several links
5) Created 'treemenus/menu.html' and 'treemenus/menu_items.html' files as advised in manual (also attached here).
6) Added '{% load tree_menu_tags %}' into one of my own template.....

And Not sure, what I do now? Not sure, where and how I use 'menu' and 'menu_item' in context? I would really appreciate any pointers or suggestions. Reading manual is not helpful mostly because, i lack deep understanding about the Django system.


I named the menu i created (using admin) as 'ngsdbviewmenu'. Ideally i would like to display it in my base_site.html so it is displayed everywhere....

Thanks a bunch in advance, Gowthaman



--
Gowthaman

Bioinformatics Research Scientist.
SBRI, 307 West lake Ave N Suite 500
Seattle, WA. 98109-5219
Phone : LAB 206-256-7188 (direct).

Stephen Burrows

unread,
Apr 19, 2012, 12:09:10 AM4/19/12
to django-...@googlegroups.com
I would recommend looking at django-mptt - it's probably more efficient, it definitely is better documented, and it seems to be significantly more active than treemenus.

You will need to implement your own "MenuItem" model, though.

--Stephen

--
You received this message because you are subscribed to the Google Groups "django-seattle" group.
To post to this group, send email to django-...@googlegroups.com.
To unsubscribe from this group, send email to django-seattl...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-seattle?hl=en.

Toby Champion

unread,
Apr 19, 2012, 12:29:28 PM4/19/12
to django-...@googlegroups.com
There's a list of Django navigation apps at http://djangopackages.com/grids/g/navigation/

Alec Koumjian

unread,
Apr 19, 2012, 3:01:20 PM4/19/12
to django-...@googlegroups.com
Gowthaman,

Can you describe the use-case? Is the idea that you have a dynamic list of resources which you want to add as navigational links?

gowtham

unread,
Apr 19, 2012, 3:14:10 PM4/19/12
to django-...@googlegroups.com
Thanks Toby and Stephen.
I actually picked this from the link suggested by Toby. Dont really know why i chose that. I will try Stephen's suggestion. 

But, I'd still give a try to tree-menus, because, that will teach me more of Django. The problem i face here is the not the app. but my understanding for django.

But, for getting things done part i will sure give a try to other apps.


On Thu, Apr 19, 2012 at 9:29 AM, Toby Champion <to...@tobychampion.co.uk> wrote:



--
Gowthaman

Bioinformatics Systems Programmer.

gowtham

unread,
Apr 19, 2012, 3:19:54 PM4/19/12
to django-...@googlegroups.com
Hi Alec,
I have a very simple application in Django (my naive attempt too).  There is no dynamic list of resources. 

Currently, I store them in dictionary. And my base_site.html template, displays them into a menu bar. This works fine.

But, I woud like to group them into sets.  In the bar i would like to display  only the group title and on mouse over/click i would like to see all the members of the group.

Not sure, if i this is what you asked?

Thanks very much for trying to help me,
Gowthaman
Gowthaman

Bioinformatics Systems Programmer.

Chris Johnson

unread,
Apr 19, 2012, 3:27:49 PM4/19/12
to django-...@googlegroups.com
It looks like you create two templates for rendering menus and individual menu items:
  * treemenus/menu.html
  * treemenus/menu_item.html (not menu_items.html)

where 'menu', 'menu_item', and 'menu_type' are context variables for the templates above, not for the template where you would like to render the menu.  

For your own template, you load the treemenu tags and then call the 'show' tag with the name of the menu you'd like to render:

{% load tree_menu_tags %}
.
.
.
{% show_menu 'ngsdbviewmenu' %}

I imagine this tag pulls what it needs from the treemenus tables and renders the menu.html templates which probably loops through every menu item rendering the menu_item.html template on each iteration.

Alec Koumjian

unread,
Apr 19, 2012, 3:28:20 PM4/19/12
to django-...@googlegroups.com
Sure, makes sense.

It seems to me like this isn't really a Django specific problem. Once you have your tree of menu items (whether through template tags or statically in the template), what you want is a good css or js package to get the expand/collapse behavior you're talking about.

I may be missing something.
Reply all
Reply to author
Forward
0 new messages