Sure, that seems fine. On Monday, December 7, 2015 at 12:13:07 PM UTC-5, Hans Soflao wrote: > > Thank you, I used the method Anthony mentioned and it worked. > Now a follow up question, in order to have access to database in this > module to assign var1 (defined in the database) to var2 (defined in the > module) what is the best method? > > For instance to have access to the latest row of data in the table1 > defined in the model as > db.define_table('Table1', > Field('F1', 'integer')) > > should I have in the model the following?: > > from gluon import current > current.db = db > > and in the module module1.py?: > > def module1(): > db = current.db > var2=db().select(db.Table1.var1, orderby=~db.Table1.id, limitby=(0, > 1))[0].var1 > > Thanks > > > > On Friday, December 4, 2015 at 9:39:35 AM UTC-5, Aydin S wrote: >> >> This might be asked before and I already found a similar question in >> here: https://groups.google.com/forum/#!topic/web2py/0k0Fvw6fmb8 >> but this seemed a bit confusing. How to write on database from within a >> module? >> I have a table defined in db.py (model) as follows: >> db.define_table('Table1', >> Field('F1', 'integer')) >> >> Now I have a variable var1 in the module module1.py that I want to write >> it into F1. >> >> var1=2 >> >> Is this similar approach to read a variable from database in a module? >> >> >> >>
-- 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.