473,396 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Python treeview and recursion: help needed

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

Jun 27 '08 #1
0 803

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
6
by: Lowell Kirsh | last post by:
I'm trying to emulate the sorted() method introduced in python 2.4. The only difference is that it takes a sequence as one of its arguments rather than being a method of the sequence class. Does my...
2
by: MSNEWS | last post by:
Hi I'm trying to use the treeview control but having a hard time trying to visualize how I'm going to achieve when I'm trying to do, as an example in the end of my program I want my treeview to...
7
by: Mike | last post by:
hi everyone! i'm searching for a tutorial or an example for how to fill a treeview with information from my ms sql database. i've found some on "code project" and other sites, but nothing like a...
206
by: WaterWalk | last post by:
I've just read an article "Building Robust System" by Gerald Jay Sussman. The article is here: http://swiss.csail.mit.edu/classes/symbolic/spring07/readings/robust-systems.pdf In it there is a...
0
by: Mailing List SVR | last post by:
Il giorno ven, 23/05/2008 alle 09.20 +0200, Mailing List SVR ha scritto: only for the records attacched is a working solution, maybe not the best one but a working one, regards Nicol
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.