Hi Everyone
I am just learning Pylons. I can manage with Mako and working with the
controller but I am having trouble with the model. I can't figure out
what I did wrong, could someone help with this error?|
AttributeError: 'module' object has no attribute 'Session'
Please see my code below.
Thanks in advance-Patrick
|
----------------------------------------------------------------------------------------------------------------------------
crap.py
import logging
from pylons import request, response, session, tmpl_context as c
from pylons.controllers.util import abort, redirect_to
from craptek.lib.base import BaseController, render
from craptek import model
log = logging.getLogger(__name__)
x = "test1"
class CrapController(BaseController):
def index(self):
# Return a rendered template
# return render('/template.mako')
# or, Return a response
return 'Helllo World'
def view(self, id):
q = model.Session.query(model.Foo)
c.content = q.limit(5)
c.title = 'sample page of crap'
c.heading = 'sample title of crap'
return render('/derived/page/view.html')
-------------------------------------------------------------------------------------------------------------------------------------------------------
__init__.py
"""The application's model objects"""
import sqlalchemy as sa
from sqlalchemy import orm
from craptek.model import meta
def init_model(engine):
"""Call me before using any of the tables or classes in the model"""
## Reflected tables must be defined and mapped here
#global reflected_table
#reflected_table = sa.Table("Reflected", meta.metadata, autoload=True,
# autoload_with=engine)
#orm.mapper(Reflected, reflected_table)
sm = orm.sessionmaker(autoflush=True, transactional=True, bind=engine)
meta.engine = engine
meta.Session = orm.scoped_session(sm)
## Non-reflected tables may be defined and mapped at module level
foo_table = sa.Table("Foo", meta.metadata,
sa.Column("id", sa.types.Integer, primary_key=True),
sa.Column("bar", sa.types.String(255), nullable=False),
)
class Foo(object):
def __str(self):
return self.id
orm.mapper(Foo, foo_table)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---