> When I add code to display the contents    'Shortname: %s' % 
> person.short_name 
> (even after I have edited the table - which I understand should trigger 
> the shortname update)
>

Updating the record will only trigger the compute field update if *all* the 
fields needed by the function are included in the updated fields. The 
compute function will not fetch non-updated fields from the database in 
order to calculate the computed value.
 

> and for the seond method    'DisplayName: %s' % person.display_name
>
> I get an attribute error...
>
> Traceback (most recent call last):
>   File "/home/peter/web2py/gluon/restricted.py", line 227, in restricted
>     exec ccode in environment
>   File 
> "/home/peter/web2py/applications/PAPILLON_AIM/controllers/default.py", line 
> 2256, in <module>
>   File "/home/peter/web2py/gluon/globals.py", line 417, in <lambda>
>     self._caller = lambda f: f()
>   File "/home/peter/web2py/gluon/tools.py", line 4241, in f
>     return action(*a, **b)
>   File 
> "/home/peter/web2py/applications/PAPILLON_AIM/controllers/default.py", line 
> 305, in view_person
>     'DisplayName: %s' % person.display_name
>   File "/home/peter/web2py/gluon/packages/dal/pydal/objects.py", line 90, 
> in __getattr__
>     raise AttributeError
> AttributeError
>

When defining a virtual field, inside the function, you must use 
row.tablename.fieldname to refer to each field, not just row.fieldname.

As an aside, why not change the get_user_short_name function to take a 
single row object rather than each of the individual field values? That 
way, instead of having to do:

Field.Virtual('display_name', lambda row: get_user_short_name(...))

you can simply do:

Field.Virtual('display_name', get_user_short_name)

In other words, as long as you are creating a function solely for this 
purpose, just give it the signature it needs without having to wrap it in a 
lambda.

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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to