Another option would be to create a ModelRegistry and then have you functions import that and grab the classes off of there.
But I think bound metadata may be what you want. It might be worth documenting that use case better, but I'm pretty swamped at the moment. Hopefully somebody can step up and help out... --Mark Ramm On Wed, May 27, 2009 at 10:06 PM, Uwe C. Schroeder <[email protected]> wrote: > > On Wednesday 27 May 2009, Mark Ramm wrote: >> You don't need to define your tables inside init_model itself, but >> init_model will be called after the metadata is setup and engine >> defined, but before your app is loaded, so it's an obvious place from >> which to manage table reflection. >> >> You can call other functions or class methods from init_model, so you >> can split things up as you choose. >> > > I think I should refine the question: > The problem with the above is that the classes one defines are local to the > init_model function. Thus a "from xxx.model import someclass" throws an > error. > I can't import the classes at the end of __init__.py as it would normally be > done, because as you pointed out, nothing is initialized and the table isn't > reflected yet, so referencing it is impossible at that point. > > Basically all I want to do is reflect the tables and map a class to the > reflected table which then at one point can simply be imported from xxx.model > In TG1 this was easy - reflect the table at the top of model.py and then just > use it in some other module where the according class and mapping is set up. > > Maybe this is a basic python scope question, but still the answer eludes me. > > Uwe > -- Mark Ramm-Christensen email: mark at compoundthinking dot com blog: www.compoundthinking.com/blog --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" 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?hl=en -~----------~----~----~----~------~----~------~--~---

