db(...).select().group_by_value(db.table.field), thanks Yair
This commit is contained in:
1 parent
620c61b51a
commit
cd20ee3875
3 files changed
+21
-3
No files matched your search
@@ -1 +1 @@
|
||||
Version 1.99.4 (2012-02-21 16:25:39) stable
|
||||
Version 1.99.4 (2012-02-22 11:32:05) stable
|
||||
@@ -120,9 +120,9 @@
|
||||
</li><li>Thadeus Burgess (validators)
|
||||
</li><li>Tim Michelsen (Sphinx documentation)
|
||||
</li><li>Timothy Farrell (python 2.6 compliance, windows support)
|
||||
</li><li>Yair Eshel (internationalizaiton)
|
||||
</li><li>Yair Eshel (internationalizaiton, DAL improvement)
|
||||
</li><li>Yannis Aribaud (CAS compliance)
|
||||
</li><li>Yarko Tymciurak (design, Sphinx documentation)
|
||||
</li><li>Yarko Tymciurak (design)
|
||||
</li><li>Younghyun Jo (internationalization)
|
||||
</li><li>Vidul Nikolaev Petrov (captcha)
|
||||
</li><li>Vinicius Assef
|
||||
|
||||
@@ -7624,6 +7624,23 @@ class Rows(object):
|
||||
"""
|
||||
return Rows(self.db,sorted(self,key=f,reverse=reverse),self.colnames)
|
||||
|
||||
def group_by_value(self, field):
|
||||
"""
|
||||
regroups the rows, by one of the fields
|
||||
"""
|
||||
if not self.records:
|
||||
return {}
|
||||
key = str(field)
|
||||
grouped_row_group = dict()
|
||||
|
||||
for row in self:
|
||||
value = row[key]
|
||||
if not value in grouped_row_group:
|
||||
grouped_row_group[value] = [row]
|
||||
else:
|
||||
grouped_row_group[value].append(row)
|
||||
return grouped_row_group
|
||||
|
||||
def as_list(self,
|
||||
compact=True,
|
||||
storage_to_dict=True,
|
||||
@@ -8000,3 +8017,4 @@ if __name__ == '__main__':
|
||||
import doctest
|
||||
doctest.testmod()
|
||||
|
||||
|
||||
Reference in new issue
Block a user