Tree View

150 views
Skip to first unread message

Max Battcher

unread,
Feb 4, 2006, 12:12:05 AM2/4/06
to django...@googlegroups.com
I hit a wall and was wondering if anyone else has hit this particular
wall. I wanted a simple "tree view" generated from my model. I figured
I might be able to do this nicely with a recursive template, but as far
as I can tell after only 3 levels (2 {% include %} blocks)
(component_tree --includes-> component_info --includes-> component_info)
Python returns a error (too much recursion depth). A contributing
factor might be inheritance, I'm not sure. 5 level inheritance on
component_tree (component_tree --extends-> base_orkin --extends-->
base_dev --extends-> base_sidebar --extends-> base).

Has anyone else experienced this? Does anyone else have any experience
to share on tree views? Otherwise I guess its time for a major refactor...

--
--Max Battcher--
http://www.worldmaker.net/

akaihola

unread,
Feb 4, 2006, 9:29:44 AM2/4/06
to Django users
See these cookbook recipes for ideas:
http://code.djangoproject.com/wiki/CookBookCategoryDataModel
http://code.djangoproject.com/wiki/ModifiedPreorderTreeTraversal

I use a custon template tag to make a tree-like navigation menu by
turning the tree into a straight list with depth information on each
item. My tree structure comes from Flatpages URLs though and not a
recursive model. Anyway I thought it's wise to do all the complex stuff
(be it recursion or otherwise) in Python in the view and have the
template deal with just a straight list.

Max Battcher

unread,
Feb 4, 2006, 11:08:53 AM2/4/06
to django...@googlegroups.com
akaihola wrote:
> See these cookbook recipes for ideas:
> http://code.djangoproject.com/wiki/CookBookCategoryDataModel

I was using this already.

> http://code.djangoproject.com/wiki/ModifiedPreorderTreeTraversal

Thanks. That's a start. I was hoping for something a bit wiser and
more generic, though... something to produce nice semantic XHTML
(<ul>s). I'll ponder on this subject a bit more later.

Julio Nobrega

unread,
Feb 4, 2006, 12:50:17 PM2/4/06
to django...@googlegroups.com
<ul>'s are possible, it's in fact what I use on my (to-be) site:

<ul>
{% for node in node_tree %}
<li style="margin-left:{% widthratio node.stack 20 100 %}%">
{{ node.body }}
</li>
{% endfor %}
</ul>

Screenshot of (a more styleshed) output here:

http://static.flickr.com/42/95381035_a51eb622dc_o.png


--
Julio Nobrega - http://www.inerciasensorial.com.br

Max Battcher

unread,
Feb 5, 2006, 6:00:41 PM2/5/06
to django...@googlegroups.com
Julio Nobrega wrote:
> <ul>'s are possible, it's in fact what I use on my (to-be) site:
>
> <ul>
> {% for node in node_tree %}
> <li style="margin-left:{% widthratio node.stack 20 100 %}%">
> {{ node.body }}
> </li>
> {% endfor %}
> </ul>

It's still not semantic (uses presentation style instead of nested
<ul>s). It's looking like if I really want a true list view I need to
build a custom tag. Right now I think I'm just going to spread the tree
out across the URL space.

Jacob Kaplan-Moss

unread,
Feb 5, 2006, 6:10:13 PM2/5/06
to django...@googlegroups.com
On Feb 5, 2006, at 5:00 PM, Max Battcher wrote:
> It's still not semantic (uses presentation style instead of nested
> <ul>s). It's looking like if I really want a true list view I need
> to build a custom tag. Right now I think I'm just going to spread
> the tree out across the URL space.

You might want to take a look at the {% recurse %} tag from the
Custard (Greenpeace) project: https://svn.greenpeace.org/viewvc/
viewcvs.py/custard/production/trunk/melt/apps/custard/templatetags/
customtags.py?rev=539&view=markup

Jacob

Reply all
Reply to author
Forward
0 new messages