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:
  form.vars.update(field2=form.vars.field1)

# and crud.update()

crud.settings.update_onvalidation=lambda form:
  form.vars.update(field2=form.vars.field1)

# with SQLFORM

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

form.vars.update(field2=form.vars.field1)):

Discussion at web2py Google Groups here

Comments

Leave a Reply

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