On 3/28/07, __wyatt <[EMAIL PROTECTED]> wrote:
>
>
>
> On Mar 28, 9:05 am, fintan <[EMAIL PROTECTED]> wrote:
> > Hi
> >
> > I'm new to python & pylons. I was wondering could someone answer some of my
> > questions. I've got the basic down in python and was looking for a web
> > framework when I came across pylons. I've gone through the tutorials and the
> > documentation.
> >
> > At the moment I'm building a user control panel that will integrate with
> > ldap. So far I've managed to set up a login page with user level controls
> > and am able to browse to different pages using links.
> >
> > I'm trying to get some stuff straight in my head.
> >
> > I've set up my database in models.__init__.py using sqlalchemy with mysql
> >
> > Is this the correct method?
> >
> > from docutils.core import publish_parts
> > from sqlalchemy import *
> > from sqlalchemy.ext.assignmapper import assign_mapper
> > from pylons.database import session_context
> > import pyucc.lib.helpers as h
> >
> > meta = DynamicMetaData()
> >
> > tables go here.
> >
> > When I try to use
> >
> > mytable = Table('Archive', meta, autoload = True)
> >
> > from paster shell I get
> >
> >  File "/usr/lib/python2.4/site-packages/sqlalchemy/schema.py", line 51, in
> > get_engine
> >     raise exceptions.InvalidRequestError("This SchemaItem is not connected
> > to any Engine")
> > sqlalchemy.exceptions.InvalidRequestError: This SchemaItem is not connected
> > to any Engine
> >
> > So I'm a little confused. Am I setting up the file right?
>
> DynamicMetaData must be connected to an engine:
>
>     meta = DynamicMetaData()
>     meta.connect(some_engine)
>
> An engine is created for you when you do this:
>
>     from pylons.database import session_context
>
> You can get at the engine with:
>
>     engine = session_context.current.bind_to
>     meta.connect(engine)
>
> Personally I find the way pylons.database works a little bit less
> explicit than I would like. Another way to create an engine is:
>
>     from pylons.database import create_engine, get_engine_conf
>     engine = create_engine(*get_engine_conf())
>     metadata.connect(engine)
>
> ``get_engine_conf`` magically looks up your sqlalchemy settings from
> the ini file you're using:
>
>     # development.ini
>     # other settings here
>     [app:main]
>     # other app:main settings here
>     sqlalchemy.dburi = postgres://bycycle:[EMAIL PROTECTED]/bycycle
>     sqlalchemy.echo = true
>
>
> > I've defined the tables using the long method to get around this.
> >
> > For each table do I have to set up a class to access that table? Kinda of
> > like the routing? Should they be in separate files under models or in the
> > same file __init__.py?  Thanks in advance
>
> I'd recommend checking out this related post and the post it links to:
>
> http://groups.google.com/group/pylons-discuss/browse_frm/thread/f33758052225c5d2/8b96885f5b6ec327?lnk=gst&q=sqlalchemy&rnum=4#8b96885f5b6ec327

You might also find the following helpful:

http://pylonshq.com/project/pylonshq/wiki/SqlAlchemyWithPylons

Best Regards,
-jj

-- 
http://jjinux.blogspot.com/

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to