db().select().as_tree()

This commit is contained in:
mdipierro
2013-10-20 22:51:03 -05:00
parent 8e1a68d461
commit d879e4a560
2 changed files with 15 additions and 1 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.7.4-stable+timestamp.2013.10.20.16.57.08
Version 2.7.4-stable+timestamp.2013.10.20.22.50.07
+14
View File
@@ -10651,6 +10651,20 @@ class Rows(object):
else:
return dict([(key(r),r) for r in rows])
def as_tree(self, parent_name='parent_id', children_name='children'):
roots = []
drows = {}
for row in self:
drows[row.id] = row
row[children_name] = []
parent = row[parent_name]
if parent is None:
roots.append(row)
else:
drows[parent][children_name].append(row)
return roots
def export_to_csv_file(self, ofile, null='<NULL>', *args, **kwargs):
"""
export data to csv, the first line contains the column names