I, too, have the same problem. I don't know how to use the model.
Then I came up with the something like a Dao (Data Access Object)
class to separate the model and use the class for all sql alchemy
related task. My plan is to keep the controller and view data out side
of sqlalchemy so that I can use the cache or berkeley db to store the
read only data.
class Store(object):
def __init__(self):
pass
def __repr__(self):
return self.title
class DataManager(object):
def __init__(self):
self.metadata = MetaData()
pass
def create_all(self):
self.metadata.create_all(checkfirst=True)
def _store_table(self):
return sa.Table('store', self.metadata,
sa.Column("uid", sa.Integer,
sa.Sequence('store_id_seq'),
primary_key=True),
sa.Column('title', sa.types.String(255), nullable
= False, unique=True),
sa.Column('summary', sa.types.String(4098),
nullable = False),
sa.Column('description', sa.types.String(1048576),
nullable = True),
sa.Column('category_uid', sa.types.Integer,
sa.ForeignKey('category.uid')),
sa.Column('image', sa.types.String(1024), nullable
= True),
sa.Column('created', sa.types.TIMESTAMP(),
default=sa.func.now())
)
def init_model(self, engine):
self.sm = orm.sessionmaker(autoflush=True, transactional=True,
bind=engine)
self.engine = engine
self.Session = orm.scoped_session(self.sm)
self.metadata.bind = engine
self.store_table = self._store_table()
self.store_table_mapper = orm.mapper(Store, self.store_table,
properties =
{'store_view_count' :
orm.relation(StoreViewCount, uselist=False, backref='store'),
'category' :
orm.relation(Category, uselist=False, backref='store'),
}
)
def get_stores(self):
... return stores... from db
Still I am looking for separation..
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---