On Tuesday, June 23, 2015 at 5:15:28 PM UTC-4, jackson.r...@quantachrome.com wrote: > > I changed the code to the following: > > *was:* > *db3.define_table('station_analysis_parameters',* > * ...* > * Field('station_preset_file', 'reference analysis_presets', > requires=IS_IN_DB(db3, 'analysis_presets.filename')),* > *...* > > *now:* > *db3.define_table('station_analysis_parameters',* > * ...* > * Field('station_preset_file', 'reference analysis_presets', > requires=IS_IN_DB(db3, 'analysis_presets.id <http://analysis_presets.id>', > '%(filename)s')),* > *...* > > Now the id of the row of the reference field appears in the grid display. > This is useless for display purposes. Can I override this and display the > actual value of the referenced filed in my grid?? While we are at it I > changed the field to type='upload' to see if that would work...This gave a > similar problem a cryptic 'file' link to download the file appears instead > of the filename. When I edit a row the edit form says that the filename > field is not set. Can I change this to show the filename? >
A reference field stores the id of the referenced record from the other table, so that is what the grid will display. To change what is displayed, you must set the "represent" attribute of the reference field. Alternatively, if you set the "format" attribute of the referenced table, you will get a default validator and "represent" attribute for any reference field that references the table. So, do the following: db3.define_table('analysis_presets', Field('filename') format='%(filename)s') db3.define_table('station_analysis_parameters', ... Field('station_preset_file', 'reference analysis_presets'), ...) With the above code, there is no need to specify the "requires" argument of the reference field because you get the IS_IN_DB validator by default. You will also get a "represent" attribute based on the "filename" field. However, if you override the default "requires" argument (as in your original code), you will no longer get the default "represent" attribute either. Anthony -- 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.