Side question: in a module, like in this example, i don't need to call commit() for the table to be created ?
2015-11-17 12:29 GMT-05:00, Yoel Benitez Fonseca <ybenit...@gmail.com>: > sorry Anthony, it is just an adaptation of my original code: > > --- > from gluon import * > import categ_model > > m_fields = list() > > fld_name = Field('name', 'string') > fld_categ = Field('categ_id', 'reference categories') > > m_fields.append(fld_name) > m_fields.append(fld_categ) > > def define_table(): > db = current.db > categ_model.define_table() > if not hasattr(db, 'my_model'): > db.define_table('my_model', *m_fields) > db.commit() > --- > > 'categ_model' is a module with the same scheme that this one, i have > tracked down the error and its seems to happen when the options widget > is constructed. It may be that my error has nothing to do with the > module declaration. > > 2015-11-17 11:54 GMT-05:00, Anthony <abasta...@gmail.com>: >> >>> >>> def define_table(): >>> if not hasattr(db, 'my_model'): >>> db.define_table('my_model', *m_fields) >>> db.commit() >>> >> >> The above refers to "db", but that is not defined anywhere. Where does >> that >> >> come from? Note, you cannot define objects such as db at the top level of >> a >> >> module, because they will only be defined once in the thread where the >> module is first imported. Instead, you should pass the db object to the >> function when it is called, or possibly add db to the current object and >> import the current object in your module. >> >> Also, I don't think you should need the db.commit(), as you are not >> manipulating any data here. >> >> Anthony >> >> -- >> 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. >> > > > -- > Msc. Yoel Benítez Fonseca > Especialista en TI > http://redevil.cubava.cu/ > Tel.: (53 32)284701 > -- Msc. Yoel Benítez Fonseca Especialista en TI http://redevil.cubava.cu/ Tel.: (53 32)284701 -- 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.