Using elixir with pylons is simple.
Switch to your virtual environment (easy_install elixir) and do the normal (paster create --template=pylons)
myapp/models/__init__.py will become
"""The application's model objects""" from sqlalchemy.orm import scoped_session, sessionmaker import elixir # replace the elixir session with pylons one Session = scoped_session(sessionmaker(autoflush=True)) elixir.session = Session elixir.options_defaults.update({ 'shortnames': True }) # use the elixir metadata metadata = elixir.metadata def init_model(engine): """Call me before using any of the tables or classes in the model""" metadata.bind = engine from entities import * elixir.setup_all()
myapp/model/entities.py will store all your Entity subclasses for example
""" myapp's ORMs """ from elixir import * import sqlalchemy class Puppies(Entity): breed = Filed(Unicode(20),nullable=False) weight = Field(Integer,nullable=False)
Finally, you will want to update myapp/websetup.py
from myapp.config.environment import load_environment from myapp.model import metadata from myapp.model.entities import * def setup_app(command, conf, vars): """Place any commands to setup myapp here""" load_environment(conf.global_conf, conf.local_conf) # Create the tables if they don't already exist metadata.drop_all(checkfirst=True) metadata.create_all() # add stuff to the database/app etc....
Normally you will not need myapp/models/meta.py so consider removing it.
Now (paster setup-app development.ini) should work.
The controllers will include the model stuff like so.
""" some controller """ from myapp.model import Session from myapp.model.entities import Puppies import sqlalchemy class MyAppController(BaseController): # actions
