Hi Massimo, Thanks for your help, i indeed used db.item.insert(**db.item._filter_fields(form.vars)) and db.subscription_item.insert(**db.subscription_item._filter_fields(form.vars)) to generate a CREATE FORM in a separate action. Now I want to create another action with an UPDATE FORM for user to modify the values, with a single table, I can use item_form=SQLFORM(db.item, item_row).process(), but with 2 tables in the same form using SQLFORM.factory, can SQLFORM.factory() take the item_row and subscription_item_row to populate the values in the UPDATE FORM from database? I tried, but didn't work. What's the best way to create an UPDATE FORM for 2 tables?
assumption above..... subscription_item_row=db(db.subscription_item.item==item.id).select().first() On Friday, April 21, 2017 at 11:23:27 PM UTC+8, Massimo Di Pierro wrote: > > You can do form = SQLFORM.factory(db.item, db.subscription_item) as long > the two tables do not have fields with the same name. Then after > > if form.process().accepted: > db.item.insert(....) > db.subscription_item.insert(....) > > where ... should be replaced by the proper fields in form.vars > > On Monday, 17 April 2017 12:09:58 UTC-5, Rudy wrote: >> >> Hi there, >> >> I am building an accounting system. When I create a quotation, if the >> item is in 'subscription' category, i want to use SQLFORM.factory(db.item, >> db.subscription_item) to generate a create form for submitting the >> necessary values. Now i want to edit these 2 tables(item and >> subscription_item have 1-1 relationship), does SQLFORM.factory() takes any >> constraint or query to specify which item I want to edit? If not, what's >> the best way to do it? Thanks in advance! >> >> Below is the simplified database tables: >> db.define_table('company', >> Field('company_name', requires=IS_NOT_EMPTY()), # >> unique=True >> format='%(company_name)s') >> >> db.define_table('quotation', >> Field('company', 'reference company'), >> Field('project_name', requires=IS_NOT_EMPTY()), >> Field('quote_amount', 'double', default=0, >> writable=False), >> auth.signature) >> >> db.define_table('category', >> Field('category_name', ondelete='NO ACTION'), # eg. >> project or subscription >> format='%(category_name)s') >> >> db.define_table('item', >> Field('quotation', 'reference quotation', >> writable=False, label='Quote Id'), >> Field('category', 'reference category', >> requires=IS_IN_DB(db, 'category.id', '%(category_name)s')), >> Field('description'), >> Field('amount', 'double', default=0), >> auth.signature) >> >> db.define_table('subscription_item', >> Field('item', 'reference item', writable=False, >> label='Item Id'), >> Field('start_date', 'date'), >> Field('end_date', 'date'), >> auth.signature) >> >> -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.