Model
db.define_table('client',
Field('name'))
db.define_table('address',
Field('client',db.client,writable=False,readable=False),
Field('street'),Field('city'))
Controller
def register():
form=SQLFORM.factory(db.client,db.address)
if form.accepts(request.vars):
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)
Notice the SQLFORM.factory (it makes ONE form using public fields from both tables and inherits their validators too).
On form.accepts this does two inserts (some data in one table and some data in the other).
Massimo
Comments (6)
0
vid-ogris-10382 6 years ago
SQLFORM. factory does not work with
auth.settings.registration_requires_verification = True
0
yuvall 9 years ago
0
gilsondev 9 years ago
0
roaldosinga 10 years ago
0
cfhowes 10 years ago
0
murphy 10 years ago