The "represent" attribute controls the display of read-only data in grids 
and read-only forms (or read-only fields). The values shown in the select 
element in a form are controlled by the validator, which defaults to 
IS_IN_DB for a reference field. The values shown in the select element 
(generated by the validator) as well as the "represent" attribute are 
controlled by the "format" argument in the definition of the referenced 
table, so the simplest approach is to change that:

    format='%(name)s, %(address)s, %(city)s')

Alternatively, you can explicitly set your own validator for the reference 

    Field('customer', 'reference customer',
          requires=IS_IN_DB(db, '', '%(name)s, %(address)s, 


On Saturday, August 5, 2017 at 2:45:49 PM UTC-4, Vic Ding wrote:
> Hi all,
> I have been hitting the wall for probably a simple problem. 
> I have 2 tables sales order and customer, db.sales_order.customer 
> reference customer table.
> db.define_table('customer',
>                 auth.signature,
>                 Field('name', 'string', requires=IS_NOT_EMPTY(), 
> label=T("Company name")),
>                 Field('address1', 'string', requires=IS_NOT_EMPTY()),
>                 Field('city', 'string'),
>                 Field('post_code', 'string', label=T("Post code")),
>                 Field('country_id', 'reference country_list', 
> requires=IS_EMPTY_OR(IS_IN_DB(db, '', '%(name)s %(code)s')), 
> label=T("Country")),
> db.define_table('sales_order',
>                 auth.signature,
>                 Field('ordernumber', 'string', label=T('Your order #'),
>                       unique=True, length=250),
>                 Field('customer', 'reference customer', label=T('Customer')),
>                 format='%(ordernumber)s'
>                 )
> On the SQLFORM editing the sales order, I would like to show more info, 
> like customer name + address1 + city, rather than just the name. I tried 
> This is the SQLFORM
> db.sales_order.customer.represent = 'change representation'
> form = SQLFORM(db.sales_order, so_id, _name='form1')
> As you can see, I changed the represent of customer filed to a static 
> string. But even this won't work. the editing form is still show the name 
> of the customer. Can someone hint me where I did it wrongly?
> Thanks!
> Cheers,
> Vic

- (Documentation)
- (Source code)
- (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 
For more options, visit

Reply via email to