一首诗 wrote:
> I have a table like this
>
> id  | name | parentid
>
> And parentid is a Foreign Key to ID.
>
> So I have a tree in my database.  My question is that, how can I
> represent it on the web as a tree.

If you can rework your database slightly you can use Modified Preorder
Tree Traversal, which is a really slick way of doing trees in
relational databases. You can get everything you need to know to
present a tree diagram with ONE database call. If you store parent-id
then you can end up hitting the database many many more times as you
climb up and down the tree.

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

And
http://www.sitepoint.com/print/hierarchical-data-database

It takes a bit of thinking about, but once it 'clicks' you'll see how
neat it is.

Barry


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to