Web2py - create multi-segment list

I have an application using web2py.

I have a table in a database named 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 scope field as a multiSelect list.

How can i do this?

Thanks in advance.

+2


source to share


1 answer


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]))
)

      

+3


source







All Articles