let say i have a table with the record that compare the product price with 
the previous product price
e.g.
*models/db.py*
def on_define_nav(table): 
table.daily_return.compute = lambda r: float(r['nav_per_unit'] ) - 
float(r['previous_nav_per_unit'] )
table.daily_return_percentage.compute = lambda r: ((float(r['nav_per_unit'] 
) - float(r['previous_nav_per_unit'] ) ) / float(r['previous_nav_per_unit'] 
) ) * 100

db.define_table('nav', 
Field('product', 'reference product'), 
Field('nav_date', 'date'),
Field('nav_per_unit', 'double'),
Field('previous_nav_per_unit', 'double'),
Field('daily_return', 'double'),
Field('daily_return_percentage', 'double'),
on_define = on_define_nav, 
format = lambda r: '%s (%s) : %s' % (r.product.name, r.nav_date, 
r.nav_per_unit) )

*currently import csv*
product nav_date nav_per_unit previous_nav_per_unit daily_return 
daily_return_percentage 
1 2017-02-01 1283.6907 1283.46 0.2307 0.0179748492 
2 2017-02-01 1493.583 1493.58 0.003 0.0002008597 
1 2017-02-02 1289.44 1288.75 0.69 0.0535402522 
*expected import csv (scrape data from another web)*
product nav_date nav_per_unit 
1 2017-02-01 1283.6907 
2 2017-02-01 1493.583 
1 2017-02-02 1289.44 

currently when i insert the data with either from web or csv i must define 
previous value during the insert, is it possible to get previous inserted 
record with the same product id in web2py dal?

thanks and best regards,
stifan

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to