SQLForm.factory and identic fields names in differents tables

11 views
Skip to first unread message

Richard Vézina

unread,
Nov 29, 2010, 3:11:33 PM11/29/10
to web...@googlegroups.com
Hello,

I would use a single form for different table that has relation. The problem it that those table are really similar. What should I do to avoid this problem? Is it possible?

Here the model

db.define_table('client',
    Field('name'),
    Field('title'),
    Field('date','date'))
db.define_table('address',
   Field('client',db.client,writable=False,readable=False),
   Field('street'),
   Field('city'),
   Field('title'),
   Field('date','date'))

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)



What does : _filter_fields(form.vars)

Does it get id value only or all the fields value store in form.vars?

Richard

pbreit

unread,
Dec 9, 2010, 9:45:07 PM12/9/10
to web...@googlegroups.com
I was wondering that myself.

I got this to almost work but it is not inserting the "address.client_id" so there's no link between the records.

Inserting into two tables seems extremely common. Hopefully this won't be too difficult.

pbreit

unread,
Dec 9, 2010, 10:09:40 PM12/9/10
to web...@googlegroups.com
My bad. I had named the field db.address.client_id. Works fine now.

But field name conflicts seem like they will be a problem at some point.
Reply all
Reply to author
Forward
0 new messages