How to do One-to-Many form Submit on one page

165 views
Skip to first unread message

Lio

unread,
May 24, 2013, 11:08:46 AM5/24/13
to web...@googlegroups.com
Hello everyone,

I have a one-to-many relation submission problem. Using the example in book (http://web2py.com/books/default/chapter/29/7#One-form-for-multiple-tables) here:

model:
db.define_table('client',
     Field('name'))
db.define_table('address',
    Field('client','reference client',
          writable=False,readable=False),
    Field('street'),Field('city'))

controller:

def register():
    form=SQLFORM.factory(db.client,db.address)
    if form.process().accepted:
        id = db.client.insert(**db.client._filter_fields(form.vars))
        form.vars.client=id
        id = db.address.insert(**db.address._filter_fields(form.vars))
        response.flash='Thanks for filling the form'
    return dict(form=form)


The user creates a record of 'client', and corresponding to this client he want to add multiple 'address' records. How to achieve this in ONE submit form? Any idea will be welcome, if too much work to create sample codes. From what I understood in the book this example only shows how to generate one form of multiple tables but not addressing issue of one-to-many relation.

Cheers.


Lio

Richard Vézina

unread,
May 28, 2013, 4:00:59 PM5/28/13
to web2py-users
You need to use ajax or try this approach :


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 web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages