Also, note that virtual fields (both the old style you have shown below and 
the new style Field.Virtual) are designed to calculate values based on 
other fields in the record. This happens at the time the records from the 
database are parsed into a Rows object, so you cannot use these for 
updating records by calling them at some later point. Instead, for this 
purpose, you would have to use Field.Method, or if you want to use the old 
style virtual fields, you would have to define the methods as "lazy" (as 
described in the documentation). Field.Method and lazy virtual fields were 
not really designed with this use in mind, but I suppose they can be used 
this way. Here's an example:

db.define_table('mytable',
    ...,
    Field.Method('change_name', lambda r, nome: r.mytable.update_record(nome
=nome)))

db.mytable(1).change_name(nome='Alessio')

Anyway, there are other ways to handle such things without resorting to 
virtual fields or classes -- for example, just writing simple functions.

Anthony

On Saturday, December 5, 2015 at 5:24:28 PM UTC-5, Anthony wrote:
>
> On Saturday, December 5, 2015 at 11:37:01 AM UTC-5, Alessio Varalta wrote:
>>
>> Hi, I have a problem..I have controller with too much code..So I want to 
>> use the logic of Java or Ruby. Have a class that represent the object of my 
>> database and implement function in this class and use this class in the 
>> Controller. The problem is that I try the VirtualField a part of web2py 
>> guide 
>>
>> in db file I create
>> class Layer_scheda(object):
>>         def change_name(self,nome):
>>             self.nome=nome
>>             self.update.update_record() 
>>
>
> It would just be self.update_record(), not self.update.update_record().
>  
>
>> after in my Controller i try 
>>
>> order_item.change_name
>> or order_item.change_name() but I have problem   change_name is not 
>> defined
>>
>
> What is order_item?
>
> 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