Look up db.table._before_insert db.table._before_update There is also
form.process(onvalidation = lambda form: .....) On Wednesday, 25 September 2013 19:34:01 UTC-5, User wrote: > > I have a model with latitude and longitude fields. The lat and lng should > be computed from the address via Google geocoding. Whenever the model is > inserted or updated I want to update the lat and lng from the address of > the model. > > In Yii PHP framework there a number of events that you can customize > surrounding models. One of them is the beforeSave event (see > http://www.yiiframework.com/doc/api/1.1/CActiveRecord#beforeSave-detail) > which is called every time before a model is saved to the database and > which I could use to call a geocode function and stuff the resulting lat > and lng into fields before saving to the database. This works no matter > where you are saving the model from. > > How can I get similar behavior in web2py? > > Currently I have a controller where in the "create()" function I use > onvalidation parameter of the form.process method to trigger the > geocoding. This works but then I would need to repeat this logic in an > "update()" controller function. And how would I get this to work when > creating or updating records from the appadmin interface? > -- 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/groups/opt_out.

