> > Hi Niphlod, thanks for your answer. > Actually, I am looking for something that I can put in my model without > touch the code of the forms, e.g., I don't want to change the code of > the admin application to solve the problem. >
In this case, I think caching in the compute_geoCode function is probably the best approach, but in general, if you want to execute a function (or set of functions) when doing inserts, updates, or deletes, you can append functions to the table's _before_insert, _before_update, _before_delete, _after_insert, _after_update, or _after_delete lists. The _after_insert functions receive a dictionary of the fields that were inserted as well as the record ID of the inserted record. After insert, you could update the record with the three values from the g.geocode() call. def compute_geoCode(r, id): g = geocoders.Google() place, (lat, lng) = g.geocode(r <http://r.name/>['name']) db.cities[id] = dict(full_address=place, lat=lat, lgt=lng) db.cities._after_insert.append(compute_geoCode) db.cities._after_update.append(compute_geoCode) That results in a second db operation (i.e., the update). An alternative would be to use a _before_insert function to call g.geocode() and cache the result, and then have the individual fields' compute functions retrieve the result from the cache. Note, the _before_ and _after_ functionality is available in trunk, but I don't think it's in the current stable release. Anthony