def change_name(row, name): row.person.update_record(name=name) The above will update the database and the local Row object.
Anthony On Friday, April 26, 2019 at 5:00:34 PM UTC-4, Lisandro wrote: > > Hi Anthony, thank you for your time. > I tried the method you suggested, but here is my problem: after calling > the method, the row object isn't updated. > > row = db.person(1) > row.change_name('Lisandro') > print(row.name) > > This doesn't print "Lisandro". > Instead, it prints the name the person had before the call. > If I want to print the new name, I have to retrieve the row again like > this: > > row = db.person(1) > row.change_name('Lisandro') > row = db.person(1) > print(row.name) > > I was wondering if it was possible to avoid having to retrieve the record > again. > > > El viernes, 26 de abril de 2019, 17:16:10 (UTC-3), Anthony escribió: >> >> def change_name(row, name): >> db(db.person.id == row.person.id).update(name=name) >> >> db.define_table('person', >> Field('name'), >> Field.Method('change_name', change_name)) >> >> row = db.person(1) >> row.change_name('Lisandro') >> >> Anthony >> >> On Friday, April 26, 2019 at 12:21:28 PM UTC-4, Lisandro wrote: >>> >>> I've been working with Virtual Fields for a while, but now I'm >>> wondering, how could I write a Virtual Field method that modifies the row >>> itself? >>> >>> I mean, I would like to do something similar that what the >>> .update_record() method does. When you call row.update_record(), the row >>> object is updated with the new values. >>> >>> I've tried returning the row object in the method definition function >>> but it doesn't work. >>> >>> I'm wondering, is it even possible to implement something like that? Any >>> comment or suggestion will be much appreciated. >>> >>> Thanks! >>> Warm regards, >>> Lisandro. >>> >> -- 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.