forked from udacity/render-cloud-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
43 lines (35 loc) · 1014 Bytes
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
from sqlalchemy import Column, String, create_engine
from flask_sqlalchemy import SQLAlchemy
import json
database_path = os.environ['DATABASE_URL']
if database_path.startswith("postgres://"):
database_path = database_path.replace("postgres://", "postgresql://", 1)
db = SQLAlchemy()
'''
setup_db(app)
binds a flask application and a SQLAlchemy service
'''
def setup_db(app, database_path=database_path):
app.config["SQLALCHEMY_DATABASE_URI"] = database_path
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db.app = app
db.init_app(app)
db.create_all()
'''
Person
Have title and release year
'''
class Person(db.Model):
__tablename__ = 'People'
id = Column(db.Integer, primary_key=True)
name = Column(String)
catchphrase = Column(String)
def __init__(self, name, catchphrase=""):
self.name = name
self.catchphrase = catchphrase
def format(self):
return {
'id': self.id,
'name': self.name,
'catchphrase': self.catchphrase}