-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
executable file
·50 lines (36 loc) · 1.44 KB
/
model.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
44
45
46
47
48
49
50
"""Models and database functions for editor's dashboard."""
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
import datetime
db = SQLAlchemy()
##############################################################################
# Model definitions
class DisneyDates(db.Model):
"""important events in disney history by date"""
__tablename__ = 'disneydates'
event_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
event_date = db.Column(db.String, nullable=False)
event_description = db.Column(db.String(2000), nullable=False, unique=True)
news_type = db.Column(db.String(100), nullable=False)
def __repr__(self):
return "%s %s" % (
self.event_date, self.event_description)
def get_event_by_date(self, date):
"""access event description by date"""
d = datetime.date.today()
day = d.day
month = d.month
##############################################################################
# Helper functions
def connect_to_db(app):
"""Connect the database to the Flask app."""
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///disneydates'
db.app = app
db.init_app(app)
if __name__ == "__main__":
# As a convenience, if we run this module interactively, it will leave
# you in a state of being able to work with the database directly.
from server import app
connect_to_db(app)
print "Connected to DB."
db.create_all()