Populate a field based on other field in web2py

We can fill a field based on another field, for example to calculate/compute a total value.

def _compute():
     return request.vars.in_time + request.vars.duration ##

db.define_table('mytable', Field('in_time','datetime'),
Field('duration', 'integer'), Field('end_time','datetime', compute = _compute))
# You can also use with crud.create()

crud.settings.create_onvalidation=lambda form:

# and crud.update()

crud.settings.update_onvalidation=lambda form:

# with SQLFORM

form.accept(...., onvalidation=lambda form:


Discussion at web2py Google Groups here

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top