I'm trying to port a simple application from pylons to get to know tg2. However,
I'm already stuck at the model setup stage and import of model classes from
controllers. I set up a sa url in development.ini. Then in model/__init__.py I
wrote
------------------------------------------------------------
def init_model(engine):
"""Call me before using any of the tables or classes in the model."""
DBSession.configure(bind=engine)
# See the following example:
#global t_reflected
#t_reflected = Table("Reflected", metadata,
# autoload=True, autoload_with=engine)
#mapper(Reflected, t_reflected)
class Inventory(DeclarativeBase):
__tablename__ = 'inventory'
id = Column(Integer, primary_key=True)
from auth import User, Group, Permission
------------------------------------------------------------
I had to add the id=... line to the class to avoid a sa traceback. I'm not sure
why that's needed if the table is reflected.
By the way I also don't understand why the example shows t_reflected = Table...
as there is no Table import (even commented out) and that's not the way
declarative_base seems to work if we are to trust
http://www.sqlalchemy.org/docs/05/plugins.html#plugins_declarative.
Anyhow, after writing the above I ran "paster setup-app development.ini" and
started the application. I can get simple controllers to work. However, I've no
idea how to access the "Inventory" class from my controller, so I could query
or update the database.
Regards,
Alex.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears Trunk" 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/turbogears-trunk?hl=en
-~----------~----~----~----~------~----~------~--~---