Partially migrated to SQLAlchemy
This commit is contained in:
parent
d75b53f008
commit
ac09c9c8d8
3 changed files with 51 additions and 3 deletions
|
@ -1,3 +1,4 @@
|
||||||
flask
|
flask
|
||||||
mock
|
mock
|
||||||
psycopg2
|
psycopg2
|
||||||
|
flask-sqlalchemy
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
import os
|
import os
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from . import config, database_postgresql, log, models
|
from flask.ext.sqlalchemy import SQLAlchemy
|
||||||
|
from . import config, database_sqlalchemy, log, models
|
||||||
|
|
||||||
|
|
||||||
log.configure_logging()
|
log.configure_logging()
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
conf = config.Config('config.json')
|
conf = config.Config('config.json')
|
||||||
|
|
||||||
|
# Load database URL for SQLAlchemy from environment
|
||||||
|
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URL']
|
||||||
|
|
||||||
# This flag tells the program it's deployed on heroku
|
# This flag tells the program it's deployed on heroku
|
||||||
if 'HEROKU' in os.environ:
|
if 'HEROKU' in os.environ:
|
||||||
conf.add(('HEROKU', 1))
|
conf.add(('HEROKU', 1))
|
||||||
|
@ -36,8 +40,13 @@ if 'SECRETKEY' in conf.config:
|
||||||
else:
|
else:
|
||||||
exit("Secret key not set.")
|
exit("Secret key not set.")
|
||||||
|
|
||||||
db = database_postgresql.DatabasePostgreSQL()
|
db = SQLAlchemy(app)
|
||||||
models.init_models(db)
|
|
||||||
|
from smash.models_sqlalchemy import *
|
||||||
|
|
||||||
|
db.create_all()
|
||||||
|
|
||||||
|
#models.init_models(db)
|
||||||
|
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
|
38
smash/models_sqlalchemy.py
Normal file
38
smash/models_sqlalchemy.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
from smash import db
|
||||||
|
|
||||||
|
|
||||||
|
class Quote(db.Model):
|
||||||
|
__tablename__ = 'quotes'
|
||||||
|
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
rating = db.Column(db.Integer)
|
||||||
|
content = db.Column(db.String())
|
||||||
|
approved = db.Column(db.Boolean)
|
||||||
|
author_ip = db.Column(db.String())
|
||||||
|
time = db.Column(db.String())
|
||||||
|
|
||||||
|
|
||||||
|
def __init__(self, content, author_ip, time):
|
||||||
|
self.rating = 0
|
||||||
|
self.content = content
|
||||||
|
self.approved = False
|
||||||
|
self.author_ip = author_ip
|
||||||
|
self.time = time
|
||||||
|
|
||||||
|
|
||||||
|
class Tag(db.Model):
|
||||||
|
__tablename__ = 'tags'
|
||||||
|
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
name = db.Column(db.String())
|
||||||
|
|
||||||
|
|
||||||
|
def __init(self, name):
|
||||||
|
self.name = name
|
||||||
|
|
||||||
|
|
||||||
|
tags_to_quotes = db.Table(
|
||||||
|
'tagsToQuotes',
|
||||||
|
db.Column('tagid', db.Integer, db.ForeignKey('tags.id')),
|
||||||
|
db.Column('quoteid', db.Integer, db.ForeignKey('quotes.id'))
|
||||||
|
)
|
Loading…
Add table
Reference in a new issue