Hi Anthony, and thanks for answering.
Actually
db.person._format = lambda row: '%s' % row.name.upper()
doesnt not affect the dropdown list building...
I had to add this
db.thing.owner_id.requires=IS_IN_DB(db,'person.id',lambda row: '%s' %
row.name.upper())
to have the dropdown list in upper case...
On Friday, September 27, 2013 2:54:17 PM UTC+2, Anthony wrote:
>
> The dropdown on a create/edit form is not controlled by the field's
> represent attribute -- instead, it is the field's IS_IN_DB validator that
> creates the dropdown. So, you could either manually override the default
> IS_IN_DB validator, or just change the db.person._format attribute, which
> will affect both the represent attribute and the IS_IN_DB validator of
> db.thing.owner_id:
>
> db.person._format = lambda r: r.name.upper()
>
> Note, with the above, you no longer need to explicitly change the
> db.thing.owner_id.represent attribute.
>
> Anthony
>
> On Friday, September 27, 2013 7:30:13 AM UTC-4, Mirko wrote:
>>
>> Here's a code example :
>>
>> db definition:
>> db.define_table('person', Field('name'), format='%(name)s')
>> db.define_table('thing', Field('name'), Field('owner_id','reference
>> person'), format='%(name)s')
>>
>> controller:
>> def manage_test():
>> db.thing.owner_id.represent=lambda id, row: '%s' %
>> db.person[row.owner_id].name.upper()
>> grid=SQLFORM.smartgrid(db.thing)
>> return dict(grid=grid)
>>
>> db.thing.owner_id.represent is not taken into account when click on add
>> or edit button.
>>
>> Many thanks!
>>
>>
>> On Friday, September 27, 2013 10:47:38 AM UTC+2, Mirko wrote:
>>>
>>> Hi,
>>>
>>> I'm using 2.5.1 and I defined a table with a default format which I
>>> override in my controller with "represent" attribute and then I call
>>> smartgrid on another table referencing the first one.
>>>
>>> When I call the controller, smartgrid shows a tabular display and the
>>> representation I overrode is taken into account, the correct string
>>> representation is displayed, fine.
>>>
>>> But when I click on add button or edit button, it appears that the
>>> default format is used for the dropdown list.
>>>
>>> I've tried many workarounds unsuccessfully, but I'm sure the new
>>> representation code line is executed and it looks like on creation or
>>> editing smartgrid is reloading the table definition after that...
>>>
>>> Or I'm I missing something ?
>>>
>>> Thanks in advance!
>>>
>>> Mirko
>>>
>>
--
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.