Created
May 8, 2014 09:27
-
-
Save jeffknupp/b12cad011777d6b13daa 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.ext.sqlalchemy import SQLAlchemy | |
db = SQLAlchemy() | |
class Cloud(db.Model): | |
__tablename__ = 'cloud' | |
id = db.Column(db.Integer, primary_key=True) | |
name = db.Column(db.String, nullable=False) | |
description = db.Column(db.String, nullable=False) | |
def __str__(self): | |
return self.name | |
class Machine(db.Model): | |
__tablename__ = 'machine' | |
id = db.Column(db.Integer, primary_key=True) | |
hostname = db.Column(db.String, nullable=False) | |
operating_system = db.Column(db.String, nullable=False) | |
description = db.Column(db.String, nullable=False) | |
cloud_id = db.Column(db.Integer, db.ForeignKey('cloud.id')) | |
cloud = db.relationship('Cloud') | |
is_running = db.Column(db.Boolean, default=False, nullable=False) | |
def __str__(self): | |
return self.hostname | |
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 models import Machine, Cloud, db | |
app = Flask(__name__) | |
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite3' | |
db.init_app(app) | |
with app.app_context(): | |
db.create_all() | |
app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment