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.
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