tags:

views:

211

answers:

1

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]))
)
Plumo
i used the first solution but when i select two regions from list there is an error message said " value not in database!" i dont know why ??
Neveen
Does it work for a single region?
Plumo