I am also searching for - 
"How to insert multiple rows on single form submit in web2py"Anyone please 
please help me.
Any clue will help!!!
Thanks in advance!!!







On Saturday, March 16, 2013 at 10:25:17 AM UTC+5:30, Richard wrote:
>
> I didn't find noting, but didn't search that much... Ask a couple of time. 
> There is many problems to resolve, and I there is no single way to solve 
> them. I develop something that may works for me, but may be not exactly 
> what you are searching for. Anyway... As soon as I get something correct I 
> show it here...
>
> Richard
>
>
> On Fri, Mar 15, 2013 at 11:24 PM, 黄祥 <[email protected] <javascript:>
> > wrote:
>
>> that's good, thanks for sharing. that's what i'm looking for, because if 
>> i'm not wrong, there is no web2py appliances that show how to add multiple 
>> data simultaneously within 1 form.
>>
>>
>> On Saturday, March 16, 2013 8:58:36 AM UTC+7, Richard wrote:
>>
>>> Yop!
>>>
>>> I am almost finish, I will publish the code I come up with when it good 
>>> enough... 
>>>
>>> :)
>>>
>>> Richard
>>>
>>>
>>> On Fri, Mar 15, 2013 at 8:24 PM, 黄祥 <[email protected]> wrote:
>>>
>>>> nice solution, with this can solve the problem to add the multiple data 
>>>> simultanously within one form.
>>>>
>>>>
>>>> On Friday, March 15, 2013 2:07:11 AM UTC+7, Anthony wrote:
>>>>>
>>>>> How about:
>>>>>
>>>>> for i in range(0,10):
>>>>>     inputs.append(db.table1.field1.clone(name='%s_%s' % (db.table1.
>>>>> field1.name, i)))
>>>>>
>>>>> The .clone() method copies the field, but you can pass in arguments to 
>>>>> replace some of the existing attributes (such as the name). I don't think 
>>>>> this is documented, though.
>>>>>
>>>>> Anthony
>>>>>
>>>>> On Thursday, March 14, 2013 8:42:21 AM UTC-4, Richard wrote:
>>>>>>
>>>>>> Hello Anthony,
>>>>>>
>>>>>> I know that, I just forget to take it in consideration in my example 
>>>>>> I guess...
>>>>>>
>>>>>> What I want to do is to create a batch insert form for a table a kind 
>>>>>> of inline edition but for insert data into database... So I would have 
>>>>>> many 
>>>>>> rows in a html table that will contains the fields a given table and 
>>>>>> only 
>>>>>> one submit button.
>>>>>>
>>>>>> I can build my form like this :
>>>>>>
>>>>>> inputs = []
>>>>>> for i in range(0,10):
>>>>>>    inputs.append(Field('field1'+'_%s' %str(i), 'type...', ...))
>>>>>>    inputs.append(Field('field2'+'_%s' %str(i), 'type...', ...))
>>>>>>
>>>>>> form = SQLFORM.factory(*inputs)
>>>>>>
>>>>>> That way I get unique distinct inputs fields.
>>>>>>
>>>>>> Then with custom form I can esealy build html table in view...
>>>>>>
>>>>>> But what I would like to avoid is to have 2 instances for field 
>>>>>> definition : one in model and one in the batch insert function because 
>>>>>> it 
>>>>>> seems to me that I can't get the field definition propertieds from 
>>>>>> model...
>>>>>>
>>>>>> I would like to know if I could get field properties from model 
>>>>>> something like that :
>>>>>>
>>>>>> inputs = []
>>>>>> for i in range(0,10):
>>>>>>     inputs.append(Field(db.table1.field1.name+'_%s' %str(i), 
>>>>>> db.table1.field1.type, ...)
>>>>>>     ...
>>>>>>
>>>>>> Thanks
>>>>>>
>>>>>> Richard
>>>>>>
>>>>>>
>>>>>> On Wed, Mar 13, 2013 at 6:28 PM, Anthony <[email protected]> wrote:
>>>>>>
>>>>>>> SQLFORM.factory creates a dummy DAL Table object with the fields 
>>>>>>> submitted, so you cannot use duplicate field names, as they are illegal 
>>>>>>> in 
>>>>>>> DAL tables. Note, technically your form can have input elements with 
>>>>>>> the 
>>>>>>> same name, but once the values are submitted to the server, the values 
>>>>>>> will 
>>>>>>> be joined together in a single list. For example, if you have three 
>>>>>>> fields 
>>>>>>> with the name "field1", request.vars.post_vars will be a list like 
>>>>>>> [value1, 
>>>>>>> value2, value3].
>>>>>>>
>>>>>>> What are you really trying to do?
>>>>>>>
>>>>>>> Anthony
>>>>>>>
>>>>>>>
>>>>>>> On Wednesday, March 13, 2013 3:31:19 PM UTC-4, Richard 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 
>>>>>>>>
>>>>>>>> inputs = []
>>>>>>>> for i in range(0,10):
>>>>>>>>     inputs.append(db.table1.field1)
>>>>>>>>     inputs.append(db.table1.field2)
>>>>>>>>
>>>>>>>> form = SQLFORM.factory(*inputs)
>>>>>>>>
>>>>>>>> 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 :
>>>>>>>>
>>>>>>>> inputs = []
>>>>>>>> for i in range(0,10):
>>>>>>>>     inputs.append(Field('field1', 'type...', ...))
>>>>>>>>     inputs.append(Field('field2', 'type...', ...))
>>>>>>>>
>>>>>>>> form = SQLFORM.factory(*inputs)
>>>>>>>>
>>>>>>>> Because doing the last example would make my code much more less 
>>>>>>>> DRY.
>>>>>>>>
>>>>>>>> Thanks
>>>>>>>>
>>>>>>>> Richard
>>>>>>>>
>>>>>>>  -- 
>>>>>>>  
>>>>>>> --- 
>>>>>>> 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 [email protected].
>>>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>>>  
>>>>>>>  
>>>>>>>
>>>>>>
>>>>>>  -- 
>>>>  
>>>> --- 
>>>> 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 [email protected].
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>  
>>>>  
>>>>
>>>
>>>  -- 
>>  
>> --- 
>> 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 [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to