db.define_table('x',Field('number','integer')) if db(db.x).isempty(): [db.x.insert(number=i) for i in range(10)]
class MyVirtualFields(object): # normal virtual field (backward compatible, discouraged) def normal_shift(self): return self.x.number +1 # lazy virtual field (because of @staticmethod) @staticmethod def lazy_shift(instance,row,delta=4): return row.x.number +delta db.x.virtualfields.append(MyVirtualFields()) for row in db(db.x).select(): print row.number, row.normal_shift, row.lazy_shift(delta=7) I made a change. Notice that @staticmethod virtualfields (aka lazy virtualfields) now take two arguments (the instance of the class that declares the virtualfield and the row obect. Also they are faster that normal "old style" virtual fields and faster if there are no virtual fields. I am still not sure about this.... let me know what you think. Massimo On Aug 20, 3:59 am, Massimo Di Pierro <massimo.dipie...@gmail.com> wrote: > I am still uneasy about this and I may still change the syntax about > the lazy virtualfields.... > > On Aug 19, 7:32 pm, rochacbruno <rochacbr...@gmail.com> wrote: > > > > > > > > > Very good! Thank you