For a while now i have been trying to simulate excel functionality without success, i have had some assistance from Anthony but i still failed to make it work but its all because of my limited imagination, i just didn't understand his solution.
https://groups.google.com/forum/#!topicsearchin/web2py/author$3Ame/web2py/QyYe78_MH4Q I am working on an application where I am changing a spread sheet document into a web application, the problem i am facing with one of the calculations is that I have to calculate for the answer_x and to get the value of answer_x i have to subtract the previously entered reading_x value from the newly entered reading_x value e,g in excel the value of answer_x is (=reading_x2 - reading_x1 ) or E1 would be (=D2-D1), i hope this is clear. This was my solution: db.define_table('subtract_value', Field('reading_x', 'integer', requires=IS_NOT_EMPTY()), Field('answer_x', compute=lambda r:r['reading_x']-r['reading_x'])) But Anthony suggested i do this: def subtract_value_before_update(*args, **kwargs): db.subtract_value.answer_x.compute = lambda r: (db.subtract_value.reading_x* -1) + r.reading_x db.define_table('subtract_value', Field('reading_x', 'integer'), Field('answer_x', 'integer', default=0)) db.subtract_value._before_update.append(subtract_value_before_update) I believe this solution can work if i only understood it but i dont, i am missing something because this code is not doing any calculations at all, I am not getting the calculated values I want but it could be the way i wrote it, i could be missing something or not doing something right! All i want i want to do is to calculate for answer_x by subtracting the previously entered value of reading_x from the newly entered value of reading_x. How can i achive my task? Regards; Mostwanted -- 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 web2py+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/d46731a7-bd34-48d1-bfaf-501672a9422f%40googlegroups.com.