Last active
December 19, 2015 19:28
-
-
Save mrjoes/6006337 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.sqlalchemy import SQLAlchemy | |
from flask.ext import admin, wtf | |
from flask.ext.admin.contrib import sqlamodel | |
from flask.ext.admin.contrib.sqlamodel import filters | |
# Create application | |
app = Flask(__name__) | |
# Create dummy secrey key so we can use sessions | |
app.config['SECRET_KEY'] = '123456790' | |
# Create in-memory database | |
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.sqlite' | |
app.config['SQLALCHEMY_ECHO'] = True | |
db = SQLAlchemy(app) | |
class Group(db.Model): | |
__tablename__ = 'groups' | |
id = db.Column(db.Integer(10), primary_key=True) | |
name = db.Column(db.String(32)) | |
def __unicode__(self): | |
return self.name | |
class User(db.Model): | |
__tablename__ = 'users' | |
id = db.Column(db.Integer(10), primary_key=True) | |
title = db.Column(db.String(120)) | |
group_id = db.Column(db.Integer(11), db.ForeignKey("groups.id"), index=True) | |
group = db.relationship('Group', uselist=False) | |
def __unicode__(self): | |
return self.title | |
if __name__ == '__main__': | |
# Create admin | |
admin = admin.Admin(app) | |
# Create DB | |
db.create_all() | |
# Add views | |
admin.add_view(sqlamodel.ModelView(Group, db.session)) | |
admin.add_view(sqlamodel.ModelView(User, db.session)) | |
# Start app | |
app.debug = True | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment