Ok, figured it out. The format specifier in the 'requires' is the magic
one, not the one in the 'represent'. So my original:
db.script.configs.requires = IS_IN_DB(db, db.config, '%(name)s',
multiple=True)
Became:
db.script.configs.requires = IS_IN_DB(db, db.config, lambda r:
format_config(r), multiple=True)
Where format_config(r) is like:
def format_config(r):
return '%s %s' % (r.name, r.detail)
- Michael
On Wednesday, July 10, 2013 3:58:54 PM UTC-4, Michael Nagy wrote:
>
> Left out the 'name' field in the 'script' file when I boiled down my
> example. Doesn't affect the issue at hand, but just to be clear:
>
> db.define_table('script',
> Field('name'),
> Field('configs', 'list:reference config'),
> format='%(name)s')
>
> - Michael
>
> On Wednesday, July 10, 2013 3:54:34 PM UTC-4, Michael Nagy wrote:
>>
>> A simplified view of my db schema, with a 'config' table and a 'script'
>> table that defines a 'configs' field that references a list of 'config'
>> records (multiple=True). I want to be able to use multiple-selection
>> listbox to edit the list of references on a 'script' record, and have the
>> list box display the formatted representation of the entries in the
>> 'config' table as per the format_config() function defined for the 'config'
>> table. I have multiple selection working fine, but nothing I have tried
>> (after a lot of googling) will change what the entries in the
>> multiple-selection listbox actually look like (I am using a vanilla SQLFORM
>> edit form).
>>
>> What am I missing? Here are my definitions (simplified):
>>
>> db.define_table('config',
>> Field('name'),
>> Field('detail'),
>> format=lambda r: format_config(r)
>> )
>>
>> def format_config(record):
>> return '%s %s' % (record.name, record.detail)
>>
>> db.define_table('script',
>> Field('configs', 'list:reference config'),
>> format='%(name)s')
>>
>> db.script.configs.requires = IS_IN_DB(db, db.config, '%(name)s',
>> multiple=True)
>> db.script.configs.represent = lambda r: format_config(r)
>>
>> I would expect that some magic in the last line should allow me to
>> control the representation of the items in the multiple-selection listbox,
>> each of which should be a 'config' table reference, but nothing I have
>> tried works - I always end up with the 'config.name' field only, without
>> the additional 'config.detail' field that I need. I can't seem to figure
>> out how to reference the items in the list of configs within the lambda, or
>> something.
>>
>> - Michael
>>
>
--
---
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.