>
> db.define_table('customers_job',
>     Field('city', db.cities),
>     Field('description', 'text'),
>     Field('customer', db.customer),
>     format="%(customer)s - %(city)s"
> )


The "format" argument to define_table() is not recursive -- the "customer" 
value in the format argument above will simply be the value of the 
"customer" field, which is an integer id referring to the db.customer 
table. The db.customer table has its own "format" argument, but that format 
is not used in constructing the formats of any referring tables. Instead of 
providing a string format, as above, you can use a callable (e.g., lambda) 
format to achieve what you want:

db.define_table('customers_job',
    Field('city', db.cities),
    Field('description', 'text'),
    Field('customer', db.customer),
    format=lambda r: '%s - %s' % (db.customer[r.customer].customer,
                                  db.cities[r.city].city)
)

That will take the id values of the record from the city and customer 
fields and use them to query the db.customer and db.cities tables, 
respectively, to obtain the customer and city names.

Anthony

Reply via email to