Created
January 16, 2014 12:37
-
-
Save mrjoes/8454346 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
from flask import Flask | |
from flask.ext.admin import Admin | |
from flask.ext.admin.contrib.sqla import ModelView | |
from sqlalchemy.orm import mapper | |
from sqlalchemy import Table, Column | |
from sqlalchemy.orm import sessionmaker | |
from sqlalchemy.engine import create_engine | |
from sqlalchemy import MetaData | |
from sqlalchemy import ( | |
Integer, Text) | |
from sqlalchemy.ext.declarative import declarative_base | |
# configure Session class with desired options | |
Session = sessionmaker() | |
# later, we create the engine | |
engine = create_engine('sqlite:///test.sqlite', echo=True) | |
# associate it with our custom Session class | |
Session.configure(bind=engine) | |
# work with the session | |
session = Session() | |
Base = declarative_base() | |
class User(object): | |
""" User profile""" | |
pass | |
meta = MetaData() | |
u = Table("u", meta, | |
Column("zuid", Integer, primary_key=True), | |
Column("username", Text)) | |
mapper( | |
User, | |
u, | |
properties = {"id": u.c.zuid} # If you comment this string, all will be ok | |
) | |
class User2(Base): | |
__tablename__ = 'u2' | |
id = Column('zuid', Integer, primary_key=True) | |
username = Column('username', Text) | |
if __name__ == '__main__': | |
app = Flask(__name__) | |
app.debug = True | |
admin = Admin(app) | |
meta.create_all(engine) | |
Base.metadata.create_all(engine) | |
#admin.add_view(ModelView(User, session)) | |
admin.add_view(ModelView(User2, session)) | |
# Start app | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment