So I think... db = DAL('sqlite://storage.sqlite')
db.define_table('map',Field('menu1'),Field('menu2'),Field('mnm_name'),Field( 'link')) import collections def build_menu(): m1, m2 = [], [] # to preserve orders m = collections.defaultdict(lambda: collections.defaultdict(list)) for row in db(db.map).select(orderby=db.map.menu1|db.map.menu2): if not row.menu1 in m1: m1.append(row.menu1) if not row.menu2 in m2: m2.append(row.menu2) m[row.menu1][row.menu2].append((row.mnm_name, row.link)) menu = [] for a in m1: submenu = [] menu.append([a, None, None, submenu]) for b, items in m[a].items(): subsubmenu = [[key, None, link] for key, link in items] submenu.append([b, None, None, subsubmenu]) return menu response.menu = cache.ram('menu', lambda:build_menu(), None) # to cache it! On Sunday, 6 August 2017 04:31:00 UTC-5, Вячеслав Анатольевич wrote: > > Thanks, Massimo! > So, i have a database table - named "map", in that table - three field - > menu1, menu2, mnm_name. > Menu mast be like that: > <top_menu> > - menu1 > - menu2 > -mnm_name > In menu1 - menu2, in menu2 - mnm_name > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.