The info has been added to the wiki. Still trying with this though. :-)
I have gotten to this point. If I have in my model:
def myrecipes(category):
db(db.recipe.category==category).select(orderby=db.recipe.title)
return db().select(db.recipe.ALL,orderby=db.recipe.title)
I can now have
from applications.cookbook.models.db import myrecipes
and the controller recipes is now
def recipes():
category=None
if request.vars.category is not None: category=request.vars.category
records=myrecipes(category)
form=SQLFORM(db.recipe,fields=['category'])
return dict(form=form,records=records)category)
I get a TypeError:
TypeError: myrecipes() takes no arguments (1 given)
Which I don't quite see why. Without the import of myrecipes though everything works as expected. Of course I would like to keep the import for clarity, and in fact I'd like to be able to have something like
:
from applications.cookbook.models import db as mydb
so I can have the reference and the namespace. I hope this makes sense! The code completion just helps me out tremendously in so many ways... I think it would be useful for others as well. I'll continue to see if this can be worked out.
On a side note, with this:
from gluon.sqlhtml import SQLFORM
from gluon.html import URL
from gluon.globals import Request
from gluon.globals import Session
from gluon.http import redirect
global db
global redirect
global request
global session
req=Request()
req=request
ses=Session()
ses=session
I have access to those objects with hinting and everything intact. I had hoped I could somehow "cast" the session and db variables but they aren't a type that can be cast. That is my current workaround although that may not be the best way. I am certainly open to suggestions! :-)
Michael