Source

alchemyadmin / src / alchemyadmin / demo / __init__.py

Full commit
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
from datetime import datetime

Base = declarative_base()
metadata = Base.metadata

class User(Base):
    __tablename__ = 'user'
    user_id = Column(Integer, primary_key=True)
    user_name = Column(String(255), unique=True)
    password = Column(String(255))
    display_name = Column(Unicode(255))
    description = Column(UnicodeText)
    birthday = Column(DateTime)


def make_app(global_conf, **app_conf):
    from alchemyadmin import Application
    conf = global_conf.copy()
    conf.update(app_conf)
    engine = engine_from_config(conf)
    metadata.bind = engine
    metadata.drop_all()
    metadata.create_all()
    Session = sessionmaker()
    session = Session()
    u = User()
    u.user_name = 'johndoe'
    u.display_name = u'John Doe'
    u.password = 'secret'
    u.birthday = datetime.now()
    u.description = """ This is demo user."""
    session.add(u)
    session.commit()

    app = Application(conf, User)
    return app