Created
December 28, 2013 20:23
-
-
Save mrjoes/8163790 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) | |
# 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() | |
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 | |
) | |
if __name__ == '__main__': | |
app = Flask(__name__) | |
app.debug = True | |
admin = Admin(app) | |
meta.create_all(engine) | |
admin.add_view(ModelView(User, session)) | |
# Start app | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment