On Wed, Mar 13, 2013 at 7:31 PM, Richard <ml.richard.vez...@gmail.com> wrote: > Hello, > > I would like to build a bunch insert form and I wouldn't have to duplicate > fields definition for SQLFORM.factory > > I try naively > > <code> > inputs = [] > for i in range(0,10): > inputs.append(db.table1.field1) > inputs.append(db.table1.field2) > > form = SQLFORM.factory(*inputs) > </code> > > But even if I get 10 inputs of each in "inputs" they all refer to the same > instance so when I render the form with SQLFORM.factory, I only get my 2 > fields, but I would have 10 of each... > > Is there a way to avoid doing this : > > <code> > inputs = [] > for i in range(0,10): > inputs.append(Field('field1', 'type...', ...)) > inputs.append(Field('field2', 'type...', ...)) > > form = SQLFORM.factory(*inputs) > </code> > > Because doing the last example would make my code much more less DRY.
Maybe something like this (not tested): inputs = [Field('field%d' % i, 'type') for i in range(1,11)] Ricardo -- --- 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/groups/opt_out.