Q:

web2py - generate multiselect list

I have an application using web2py.
I have a table in the database called member:
db.define_table("member",
  SQLField("membership_id", "integer",notnull=True),
  SQLField("first_name", "string", notnull=True,length=100),
  SQLField("region", db.region))

and I want to display the region field as multiSelect list.
How can I do this?
Thanks in advance.

A:

You can use IS_IN_DB() to create a select box from another database table:
form = SQLFORM.factory(
    Field('region', requires=IS_IN_DB(db, db.region.id, '%(name)s'))
)

Or use IS_IN_SET() for manual data:
regions = (1, 'a'), (2, 'b'), (3, 'c')
form = SQLFORM.factory(
    Field('region', requires=IS_IN_SET([r[0] for r in regions], labels=[r[1] for r in regions]))
)

