I assume you are expecting it to use the "country" table's "format"
attribute to show the country name rather than the id. However, that only
works automatically if (a) the field in question is a reference field (it
is not in your first example), and (b) you do not explicitly set your own
validator for the reference field (in which case, web2py automatically sets
both a default validator and a default "represent" attribute). Because you
have set your own validator in the second example (with the reference
field), you also need to set an explicit "represent" attribute to display
the field in read-only contexts (i.e., read-only forms, grids, and
SQLTABLE's).
Anthony
On Saturday, February 16, 2013 6:19:19 AM UTC-5, Edwin Haver wrote:
>
> Hello,
>
> I have created a grid with SQLFORM but the grid shows the country id
> instead of the country name. The form shows the name as expected but the
> grid does not. However, if I use 'reference country' it does but then I
> cannot leave the country empty in the account. Is there an easy way, other
> than using a join in the grid query, to show the country name in the grid?
>
> Here are the table definitions:
> db.define_table('country',
> Field('code', unique=True, required=True),
> Field('name', required=True),
> auth.signature,
> format='%(name)s'
> )
> db.define_table('account',
> Field('account_owner','reference auth_user'),
> Field('account_name'),
> Field('billing_country', requires=IS_EMPTY_OR(IS_IN_DB(db,db.country.
> id,'%(name)s'))),
> format='%(account_name)s',
> )
>
> Even when using the following it does not show the country name.
> Field('shipping_country','reference country',requires=IS_EMPTY_OR(
> IS_IN_DB(db, db.country.id,'%(name)s'), null=None)),
>
>
> I appreciate your help.
>
> Regards, Edwin.
>
>
>
--
---
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.