On Thu, Oct 16, 2008 at 2:41 PM, cropr <[EMAIL PROTECTED]> wrote:
>
> wrt to organizing the model into different files, I've changed the
> scheme that's is autogenerated in 0.9.7rc2.
>
> My __init__.py looks like
>
> ##########################
> from sqlalchemy import MetaData
> from sqlalchemy.orm import scoped_session, sessionmaker
>
> engine = None
> meta = MetaData()
>
> def init_model(engine):
> """Call me before using any of the tables or classes in the
> model"""
> sm = sessionmaker(autoflush=True, autocommit=False, bind=engine)
> meta.engine = engine
> meta.Session = scoped_session(sm)
>
> # below are all individual classes
> from user import *
> from item import *
> from folder import *
> from page import *
> ###########################"
>
> every class file contains the tabel definition, the class defintion
> and the mapper. example
> page.py, containing, Page a derived class from Item
>
> ############################
> from sqlalchemy import MetaData, Column, Table, types, ForeignKey
> from sqlalchemy.orm import mapper, relation, backref
>
> from project.model import *
>
> page = Table('page', meta.metadata,
> Column('id', types.Integer, ForeignKey('item.id'),
> primary_key=True),
> Column('path', types.String(255)),
> Column('language', types.String(2)),
> Column('label', types.String(255)),
> )
>
> class Page(Item):
> def __init__(self, identifier, **arg):
> self.identifier = identifier
> for (k,v) in arg.iteritems():
> setattr(self,k,v)
>
> mapper(Page, page, inherits=Item, polymorphic_identity='page')
> ###############################"
>
> but of course this all is a personal preference
>
> Ruben
I wouldn't mind to also have table + mapping inside a file with class.
But there are some issues with mapping using 'autoload' - engine does
not exist yet. Isn't it?
T.
--
_i______'simplicity_is_the_key'__________tomasz_nazar
_ii____'i_am_concern_oriented'________________JKM-UPR
_iii__'patsystem.sf.net'___________________linux_user
_'aspectized.com'___________________________prevayler
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---