[英]How to add dynamically created tables to SQLFORM in web2py
I have defined counter and dict variables in controller. 我在控制器中定义了计数器和字典变量。
I can define tables dynamically. 我可以动态定义表。
for x in range(0,counter+1):
dict['%s' % x] = db.define_table('example_table_%s' % x,
Field('example_field', type='string', ...)
...
)
I can add all the created tables manually when the counter value is '2'. 当计数器值为“ 2”时,我可以手动添加所有创建的表。
form = SQLFORM.factory(
db.some_table,
db.another_table,
dict['0'],
dict['1'],
dict['2'],
submit_button='Submit')
How do I dynamically add all the created tables to the SQLFORM? 如何动态地将所有创建的表添加到SQLFORM?
There doesn't seem to be any need for a dictionary. 似乎不需要字典。 Just put the tables in a list.
只需将表放在列表中即可。
tables = [db.define_table('example_table_%s' % x,
Field('example_field', type='string', ...)
...
)
for x in range(0, counter+1)]
form = SQLFORM.factory(*tables)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.