Created
March 1, 2012 03:35
-
-
Save hunt3r/1947065 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
models/__init__.py: | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy.orm import scoped_session, sessionmaker | |
DBSession = scoped_session(sessionmaker(autoflush=True)) | |
Base = declarative_base() | |
def initialize_sql(engine): | |
DBSession.configure(bind=engine) | |
Base.metadata.bind = engine | |
Base.metadata.create_all(engine) | |
models/Artifact.py: | |
from visionare.models import Base | |
from sqlalchemy import (Column, Unicode, Integer, Text, VARCHAR, DateTime) | |
class Artifact(Base): | |
__tablename__ = 'artifacts' | |
id = Column('artifact_id', Integer, primary_key=True) | |
name = Column('name', VARCHAR(300)) | |
data = Column('data', Text) | |
date_added = Column('date_added', DateTime) | |
date_updated = Column('date_updated', DateTime) | |
def __init__(self, name, data): | |
self.name = name | |
self.data = data | |
root __init__.py: | |
from sqlalchemy import engine_from_config | |
from pyramid.config import Configurator | |
from visionare.models import initialize_sql | |
def main(global_config, **settings): | |
""" This function returns a Pyramid WSGI application. | |
""" | |
config = Configurator(settings=settings) | |
config.add_route('home', '/') | |
config.scan('visionare.models') # the "important" line | |
engine = engine_from_config(settings, 'sqlalchemy.') | |
initialize_sql(engine) | |
config.add_static_view('static', 'static', cache_max_age=3600) | |
# other statements here | |
config.scan() | |
return config.make_wsgi_app() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment