Is detail_coa the same or nearly the same for all of these tables? If so, do you really need separate tables, rather than a single table that simply includes an extra field on which to partition it?
On Tuesday, July 25, 2017 at 11:12:34 PM UTC-4, 黄祥 wrote: > > let say i have table that will create a new table base on user input on > that table > *e.g.* > *models/db_schema_1_chart_of_account.py* > def __after_insert_chart_of_account(f, id): > name = f['name'] > table_name = name.replace(' ','_').lower() > filename = os.path.join(request.folder, 'models', 'db_schema_3_%s.py') % > (table_name) > if not os.path.exists(filename): > define_table = "db.define_table('%s', detail_coa)" % (table_name) > file = open(filename, "w") > file.write('# -*- coding: utf-8 -*-') > file.write('\n') > file.write(define_table) > file.close() > > *models/db_schema_2_account.py* > def __after_insert_account(f, id): > name = f['name'] > query_ar = (db.chart_of_account.classification == 'Account Receivable') > row_ar = db(query_ar).select().last() > code_ar = int(row_ar.code) + 1 > db.chart_of_account.insert(code = code_ar, name = 'Account Receivable %s' > % (name), > classification = 'Account Receivable') > query_ap = (db.chart_of_account.classification == 'Account Payable') > row_ap = db(query_ap).select().last() > code_ap = int(row_ap.code) + 1 > db.chart_of_account.insert(code = code_ap, name = 'Account Payable %s' % > (name), > classification = 'Account Payable') > > *controllers/install.py* > def index(): > db.chart_of_account.bulk_insert([ > {"code" : "110", "name" : "Account Receivable", > "classification" : "Account Receivable"}, > {"code" : "200", "name" : "Account Payable", > "classification" : "Account Payable"}, > ] ) > db.account.bulk_insert([ > {"name" : "Account0"}, > {"name" : "Account1"}, ] ) > > *Question :* > - is it best practice to do like example code above? tested it with small > data (install/index) but feel slow respond, because perhaps, the table in > models is load in every request, even the current data is small. any others > ideas? > > thanks and best regards, > stifan > -- 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.