> # Road table, some winding roads are both street and avenue
> db.define_table('road',
>     Field('name', 'string', length=32, unique=True, required=True, 
> notnull=True, label='Road Name'),
>     Field('is_street', 'boolean', default=False),
>     Field('is_avenue', 'boolean', default=False),
>     format='%(name)s'
>     )
>
 

> db.define_table('address', 
>     Field('street_id', "reference road", label='Street'),
>     Field('avenue_id', "reference road", label='Avenue'),
>     #format='%(street_id)s %(avenue_id)s',
>     on_define=set_address_requirements
>     )
>

"format" attributes are not applied recursively, so if your format for the 
db.address table requires pulling values from the db.road table, you will 
need to create a function that does so explicitly:

db.define_table('address',
    ...,
    format=lambda r: '%s %s' % (r.street_id.name, r.avenue_id.name))

Keep in mind that when the "format" attribute is used to create the 
"represent" attribute of a reference field, it already involves one 
recursive select for each record. In this case, because another linked 
table is involved, there is now another level that requires a recursive 
select (in fact, two additional recursive selects because there are 
separate street_id and avenue_id records). If you need to display a lot of 
records from the equipment table, this could be inefficient (three 
additional selects per record).

As an aside, what is the nature of the data model? Is an address defined as 
the intersection of a street and an avenue?

Anthony

>

-- 
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/d/optout.

Reply via email to