On Wednesday, June 22, 2011 12:28:39 AM UTC-4, toan75 wrote: > > Thank Anthony. It was clear to me. > I find it takes longer to create the many data table (db.define_table). It > will work if I put the define_table to modules? You have an example?
Others may have suggestions, but there are at least a couple possibilities. You could create a function or class in a module that takes your db object as an argument and creates some tables, and then call that function/class from a model (conditionally, only when needed) or from a controller. Alternatively, you could use the new 'current' object. Do 'from gluon import current' (which is a thread local storage object), and then add something like current.app.db = db. Then you can import 'current' into your module and the module will have access to current.app.db. For an example, you can see how Auth, Crud, and Mail are implemented in /gluon/tools.py. They make use of both methods above -- they reference the 'current' object to access the 'request' object (via current.request), but the 'db' object is passed to them as an argument. Anthony