On Monday, April 18, 2016 at 10:53:15 AM UTC-4, Bartek Celary wrote:
>
> Hello,
>
> I am just starting out in w2p. Could you please advise how to approach 
> this kind of scenario?
>
> I need a following db design:
>
> db.define_table('person',
>                 Field('first_name'),
>                 Field('last_name'),
>                 format='%(last_name)s, %(first_name)s')
>
> db.define_table('client',
>                 Field('person_id', 'reference person'),
>                 format=lambda r: '%s, %s' % (r.person.last_name, r.person.
> first_name))
>

In "lambda r", the "r" is the record from the db.client table, and you have 
not defined a field named "person" -- therefore, r.person triggers an 
AttributeError. Instead, it should be r.person_id. Alternatively, change 
the name of the "person_id" field to "person" (in web2py, it is fairly 
common to name reference fields the same as the table they reference, 
rather than appending "_id").

Same problem with the table below.
 

>
>
> db.define_table('student',
>                 Field('person_id', 'reference person'),
>                 Field('client_id', 'reference client'),
>                 format=lambda r: '%s, %s' % (r.person.last_name, r.person.
> first_name))
>
>
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