On Fri, Jun 17, 2011 at 10:02 AM, Manuele Pesenti <[email protected]
> wrote:
> do you mean that in this way my module knows all my db table models?
> right??
Nop,
from gluon import * # this let the module to know all classes under gluon
package as dal, html, validators
If you are defining your db and tables under /models and If you want you
module to know your db tables, you have two options:
*# Pass it to the module:*
*<controllers/default.py>*
def index():
from modulex import MyClass
myobject = MyClass(database=db) # passing db to the class __init__
lower = myobject.value
upper = myobject.my_method()
return dict(u=upper, l=lower)
*</controllers>*
*# Use the current object *
*
*
*
*
*<in models>*
*
*
db = DAL(...)
db.define_table(.........)
from gluon import current
current.database = db
*
*
*</models>*
*
*
*
<modulex.py>
from gluon import *
db = current.database
**
# do whatever you want with db
**
# dont forget that in modules you need db.commit()
class MyClass(object):
def __init__(self, value):
self.value = value
def my_method(self):
return self.value.upper()
</modulex.py>
*
*
*
*
*