Python treeview and recursion: help needed
Mailing List SVR
lists at svrinformatica.it
Fri May 23 10:10:33 EDT 2008
Il giorno ven, 23/05/2008 alle 09.20 +0200, Mailing List SVR ha scritto:
> Hi,
>
> I have a database with the following structure:
>
> id name sublevel
>
> for example
>
> 1 Node1 None
> 2 Node2 1
> 3 Node3 2
> 4 Node4 None
> 5 Node5 1
> 6 Node6 5
> ....
> ....
>
>
> where Node1 and Node4 are treeview's master nodes, Node2 is a subnode of
> Node1, Node3 is a subnode of Node2, Node5 is a subnode of Node1 and
> Node6 a subnode of Node5 and so on
>
> I need a recursive function to populate treeview and I'm stuck on this
> function :confused:
>
> I need a list where I have the master node with child node inside and if
> a child node as others child nodes, I need thess nodes inside the child
> nodes.
>
> Something like this:
>
> [
> {"id":1,"name":"Node1","Childs":[{"id:2","name":"Node2","Childs":[{"id":3,"name":"Node3","Childs":[]}]},
> {"id":5,
> "name":"Node5","Childs":[{"id":6,"name":"Node6","Childs":[]}]}]},{"id":4,"name":"Node4","Childs":[]}
> ]
>
> I'm using django so I access the data as
>
> all=Data.objects.all()
>
> and I can do something like
>
> for a in all:
> print a.id
> print a.name
>
> to get database value.
>
> Any help is appreciated,
>
> thanks,
> Nicola
>
> --
> http://mail.python.org/mailman/listinfo/python-list
only for the records attacched is a working solution, maybe not the best
one but a working one,
regards
Nicol
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ricorsioneid.py
Type: text/x-python
Size: 2085 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20080523/f927242e/attachment-0001.py>
More information about the Python-list
mailing list