Chapter 7 of the book covers this pretty well. http://web2py.com/book/default/chapter/07#Database-Validators

I would use the .requires attribute of the field.

Ex

To display the name and return the name...
db.tableName.name.requires = IS_IN_DB(db, 'person.name', '%(name)s', zero='choose one')

To display the name and return the id
db.tableName.id.requires = IS_IN_DB(db, 'person.id', '%(name)s', zero='choose one')

Hope that helps....

    -Jim

On 11/15/2011 4:20 AM, annet wrote:
To represent referenced records in select/option drop-downs the web2py
book gives two options:

db.define_table('person', Field('name'), format='%(name)s')

db.define_table('person', Field('name'), format='%(name)s %(id)s')


In an application I need a drop down that inserts a name as a value
and I need a drop down that inserts an id as a value. Do I use the
first option for the former and the second option for the latter?


Kind regards,

Annet.




Reply via email to