On Sep 8, 3:45 pm, Mike Orr <[email protected]> wrote: > On Tue, Sep 8, 2009 at 3:26 PM, Wyatt > > > > Baldwin<[email protected]> wrote: > > > On Sep 8, 1:28 pm, Mike Orr <[email protected]> wrote: > >> On Tue, Sep 8, 2009 at 1:17 PM, gsk<[email protected]> wrote: > > >> > Hi, > >> > Newbie question: I am using SqlAlchemy for Postgresql backend. I have > >> > setup a schema in the db where all the tables I need exist. So, I have > >> > the ORM class as below where I would dynamically pass the value for > >> > the schema: > > >> > class Foo(Base): > >> > __tablename__ = 'foo_table' > >> > __table_args__ = {'schema': someschema} > > >> > ... > > >> > I have put the db schema value in test.ini file hoping to use > >> > pylons.config. But, apparently, Pylons config object is not yet setup > >> > when model/__init__.py is initialized. Any suggestions on how I could > >> > get around this? (I've hardcoded the schema at the moment but need to > >> > parameterize as the dev and test environments use different postgresql > >> > schema spaces) > > >> Er, I'm not sure if you can do that. > > > If you're careful with your imports, this should be possible. > > > For example, you could define your Foo class in model/foo.py, then > > make sure that model.foo isn't imported until after app initialization > > occurs (i.e., after make_app runs). This should be pretty easy if you > > only import model.foo from your controller modules. > > Part of my approach was to ensure the entire model or any part of it > can be imported without the rest of the application, which is useful > in standalone maintenance utilities.
I am totally on board with that approach. :) In fact, I usually prefer to put my model into an entirely separate package--not buried within any particular app (Web, desktop, console, etc). I was only proposing something that might work for the OP or for any simpler case where such separation isn't needed (though I'm of a mind that it almost always will be). --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
