Thomas Wittek wrote:
> Hi!
>
> I'm getting to a point where my model.py gets too large for one file/
> module (for my taste).
> So I tried to split it up into several modules, but I ran into
> problems with the dependencies between the classes/mappings and I
> wonder how the other TG users handle this.
>
> A simple example would be a model handling `users` that can
> `participate` at an `event`.
> I would like to create a module for all user-related stuff (in my case
> this would be an extended TG-Identity model) and another one for the
> event-related tables/classes/mappings.
>
> Unfortunately, the mapper for the user references a participation from
> the event module and the participation table references the user
> table.
> So I have a cyclic dependency between those modules.
> In one single module you can easily resolve this dependency by
> defining *all* tables first, then all classes and last, all mappings.
> You cannot easily do this when you split up your model into several
> modules -- at least if you have the tables, classes and mappings for
> one sub-model in one module.
> My solution was to defer the creation of the mappings by putting them
> in functions that get called after all models have been loaded.
> Is there a better/more convenient way of doing this?
> How would you organize your model (and your imports, mappings)?
I usually split my models, even one-mapped-per-class when classes are
big, and almost always managed to solve this by using backref's where
appropiate to create an "invisible back arrow" that doesn't cause a
circular dependency between python modules. If the backref is complex
you can use the backref function to pass additional parameters:
relation(User, backref=backref("events", foo="bar", etc..))
HTH,
Alberto
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---