Instead, why don't you try: db.define_table('ItemOwners', Field('ItemName', requires=IS_IN_DB(db, 'ItemRecords.ItemName')))
Anthony On Friday, November 15, 2013 3:35:17 AM UTC-5, Sarbjit wrote: > > > My requirement was to show drop down list for a field generated using GRID > by using the values defined in another table. > > Below is the code used: > > *Models:* > > # coding: utf8 > db = DAL('sqlite://storage.sqlite') > from gluon.tools import Crud, Auth > auth=Auth(globals(),db) > auth.define_tables(username=False) > db._common_fields.append(auth.signature) ## adds signature fields to all > tables > db.define_table('ItemRecords', Field('ItemName')) > db.define_table('ItemOwners', Field('ItemName')) > > *Controllers:* > > def testpage(): > table_name = 'ItemRecords' > field_name = 'ItemName' > rows1 = db(db.ItemRecords.ItemName!=None).select() > opts_dropdown = [] > for row1 in rows1: > opts_dropdown.append(row1.ItemName) > opts_dropdown = list(set(opts_dropdown)) # Make it unique > element_id = 'ItemOwners_ItemName' > custom_select = SELECT(opts_dropdown, _id=element_id) > grid = SQLFORM.smartgrid(db.ItemOwners,csv=False,user_signature=False) > grid.element('input',_id=element_id, replace=custom_select) > return dict(grid=grid) > > def testpage1(): > grid = SQLFORM.grid(db.ItemRecords,csv=False,user_signature=False) > return dict(grid=grid) > > *Views :* > > {{=grid}} > > # For both testpage and testpage1 > > Now Insert few records to Itemrecords table using testpage1. Try to insert > new record in ItemOwners table using testpage view, you'll see the drop > down with the values from ItemRecords table. Add a record and reload > testpage view, you;ll see that the ItemName record will be seen empty in > grid. > > If I don't use replace in testpage view (To show drop down), then it works > fine. > > Can some one please help me to resolve this issue, by using replace, I am > getting drop down values, then why are those not getting saved. > -- 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/groups/opt_out.