Hi, I'm trying to set up a dropdown on a form to have representation text that merges information from multiple tables.
The table setup is one where I'm tracking users and datasets associated with projects. Because project details can get updated, I have a permanent project id, and the details (including the title) are stored in a different table and the version associated with an id can be updated. So the (stripped down) tables are: # Permanent Project ID. The project details id gets updated as new versions arrive db.define_table('project_id', Field('project_details_id', 'integer')) # A table of details. db.define_table('project_details', Field('project_id', 'reference project_id'), Field('version', 'integer'), Field('title','string', notnull=True) format='%(title)s') # Tag users to projects db.define_table('project_members', Field('project_id', 'reference project_id', notnull=True), Field('user_id', 'reference auth_user', notnull=True)) # Tag datasets to projects db.define_table('datasets', Field('uploader_id', 'reference auth_user'), Field('project_id', 'reference project_id'), Field('file','upload')) So, the controller below is to allow users to populate the datasets table. I'm using requires locally to restrict a user to uploading datasets for projects that they are a member of. def submit_dataset(): """ Controller to upload a dataset to the website for checking """ # restrict choice of projects for standard users query = db((db.project_members.user_id == auth.user.id) & (db.project_members.project_id == db.project_id.id) & (db.project_id.project_details_id == db.project_details.id)) db.datasets.project_id.requires = IS_IN_DB(query, 'project_id.id', 'Project %(id)s', zero='Select project.') form = SQLFORM(db.datasets, fields=['project_id', 'file']) This works well, but the resulting dropdown only has the project ID number, which is going to be confusing. What I'd like to do is change the representation of the dropdown so that it uses the project ID and project title, but only the id is stored in the datasets table. I guess I was hoping that something like this would work: db.datasets.project_id.requires = IS_IN_DB(query, 'project_id.id', '(%(id)s) %(db.project_details.title)s', zero='Select project.') Any solutions? Many thanks, David -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.