Skip to content

Instantly share code, notes, and snippets.

@pawl
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save pawl/e4fed4d578e8f12f271d to your computer and use it in GitHub Desktop.

Select an option

Save pawl/e4fed4d578e8f12f271d to your computer and use it in GitHub Desktop.
from flask import Flask, request
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.admin.contrib import sqla
from flask.ext.admin import expose, Admin
app = Flask(__name__)
app.config['DATABASE_FILE'] = 'sample_db.sqlite'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + app.config['DATABASE_FILE']
db = SQLAlchemy(app)
class Model(db.Model):
id = db.Column(db.Integer, primary_key=True)
uncheck_me = db.Column(db.Boolean, default=True)
other_field = db.Column(db.String)
class ModelAdmin(sqla.ModelView):
@expose('/edit/', methods=('GET', 'POST'))
def edit_view(self):
view = super(ModelAdmin, self).edit_view()
print request.form
return view
admin = Admin(app)
admin.add_view(ModelAdmin(Model, db.session))
def build_sample_db():
db.drop_all()
db.create_all()
db.session.add(Model())
db.session.commit()
if __name__ == '__main__':
build_sample_db()
app.run(debug=True, host="0.0.0.0", port=5001)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment