Basic example: db.define_table('contact', Field('contract_start','date'), Field('contract_length','string'), Field('contract_renewal','date', writable=True, readable=True, compute=lambda r: (r['contract_start']+r['contract_length']))
db.contact.contract_start.requires = IS_DATE(format=T('%m-%d-%Y'), error_message='Must be MM-DD-YYYY!') db.contact.contract_renewal.requires = IS_DATE(format=T('%m-%d-%Y'), error_message='Must be MM-DD-YYYY!') db.contact.contract_length.requires = IS_IN_SET(['6 months', '1 year', '2 year's, '3 years']) Thanks. As far as the DAL goes, I am using SQLite, and I know I can do something like this to add a specific time period to a date by using the following statement - INSERT date('now','+10 day'); Is there a DAL equivalent? I didn't see anything in the book. Seems like this would be too low of a function to be part of the DAL. On Mon, Apr 15, 2013 at 11:52 AM, Niphlod <niph...@gmail.com> wrote: > > either with onvalidate or with a computed field .... read it on the book > ^_^ > http://web2py.com/books/default/chapter/29/06#Computed-fields > > > On Monday, April 15, 2013 8:34:48 PM UTC+2, Michael Herman wrote: >> >> I'm slightly confused on how to make a calculation and then update a SQL >> field after a form is validated. >> >> What I'm trying to do is this: >> http://www.screencast.com/users/Mike_Extentech/folders/Jing/media/70a2511b-f978-458b-8d4c-9a635b191a33 >> >> Essentially, the end_date field is dependent on the data inputed into the >> other two fields, start_date and length. So once the form is validated, a >> calculation is triggered then the data is inserted into the database for the >> end_date field. >> >> Does that make sense? >> >> I'm also using the SQLFORM.grid default view for adding records. >> >> >> Thanks! >> > -- > > --- > You received this message because you are subscribed to a topic in the > Google Groups "web2py-users" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/web2py/f-14OLOhKpM/unsubscribe?hl=en. > To unsubscribe from this group and all its topics, send an email to > web2py+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > -- --- 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/groups/opt_out.