0

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'.

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?

Henri
  • 5
  • 1

1 Answers1

0

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)
Anthony
  • 25,466
  • 3
  • 28
  • 57
  • Are you asking an additional question? If so, I don't get what you are looking for. Maybe edit the original question or create a new one. – Anthony Dec 16 '15 at 03:21