-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodel.py
39 lines (26 loc) · 1010 Bytes
/
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
from datetime import datetime
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class Reservation(db.Model):
__tablename__ = "reservations"
reservation_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
username = db.Column(db.String)
start_time = db.Column(db.DateTime(timezone=True))
def __repr__(self):
return f"<User username={self.username} start_time={self.start_time}>"
def to_dict(self):
return {
"reservation_id": self.reservation_id,
"username": self.username,
"start_time": self.start_time.isoformat(),
}
def connect_to_db(flask_app, db_uri, echo):
flask_app.config["SQLALCHEMY_DATABASE_URI"] = db_uri
flask_app.config["SQLALCHEMY_ECHO"] = echo
flask_app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db.app = flask_app
db.init_app(flask_app)
print("Connected to the db!")
if __name__ == "__main__":
from api import app
app.app_context().push()