[web2py] Re: Hiding items in foreign key dropdown menus?
IS_IN_DB can take a set. It is mentioned in the book. Use something like: db(db.fruits.isactive==True) in place of db.fruits On Tuesday, August 21, 2012 10:13:52 PM UTC+1, joe wrote: I have a support table with the field 'isactive', which is a boolean. When someone is adding to a table that is supported by the first table, I want only items with isactive as True to be included in the dropdown. Here is some simplified example code: model -- db.define_table('fruits', Field('name', requires = IS_NOT_EMPTY()), Field('isactive', 'boolean')) db.define_table('grocery', Field(fruits', db.fruits, requires = IS_EMPTY_OR(IS_IN_DB(db, db.fruits, '%(name)s')), represent=lambda id, row: db.fruits(id).name if id else '')) --- In a SQLFORM generated from the grocery table, how can I only show fruits that are active? Thanks! -Joe Peacock --
[web2py] Re: Hiding items in foreign key dropdown menus?
On Tuesday, August 21, 2012 5:49:48 PM UTC-4, villas wrote: IS_IN_DB can take a set. It is mentioned in the book. Use something like: db(db.fruits.isactive==True) in place of db.fruits Almost. Use that in place of db (the first arg of IS_IN_DB, which defines a set), not db.fruits (the second arg, which should remain as is). Anthony --
[web2py] Re: Hiding items in foreign key dropdown menus?
Nearly got it! Thanks Anthony. On Wednesday, August 22, 2012 12:16:36 AM UTC+1, Anthony wrote: On Tuesday, August 21, 2012 5:49:48 PM UTC-4, villas wrote: IS_IN_DB can take a set. It is mentioned in the book. Use something like: db(db.fruits.isactive==True) in place of db.fruits Almost. Use that in place of db (the first arg of IS_IN_DB, which defines a set), not db.fruits (the second arg, which should remain as is). Anthony --