-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
135 lines (99 loc) · 2.25 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
"""SQLAlchemy models for Dolt."""
from datetime import date, datetime
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class User(db.Model):
""" Users in the app """
__tablename__ = 'users'
id = db.Column(
db.Integer,
primary_key=True,
)
name = db.Column(
db.String(),
nullable=False
)
email = db.Column(
db.String(255),
nullable=False
)
slack_user_id = db.Column(
db.Text,
nullable=False
)
slack_team_id = db.Column(
db.Text,
nullable=False
)
slack_img_url = db.Column(
db.String(),
nullable=False
)
def get_firstname(self):
return name.partition(' ')[0]
class Task(db.Model):
""" Tasks are to-do items """
__tablename__ = 'tasks'
id = db.Column(
db.Integer,
primary_key=True,
)
title = db.Column(
db.Text,
nullable=False
)
description = db.Column(
db.Text
)
due = db.Column(
db.Date,
default=date.today().isoformat()
)
important = db.Column(
db.Boolean,
default=False,
nullable=False
)
completed = db.Column(
db.Boolean,
default=False,
nullable=False
)
created_at = db.Column(
db.DateTime,
default=datetime.now(),
nullable=False
)
user_id = db.Column(
db.Integer,
db.ForeignKey('users.id', ondelete='cascade'),
nullable=False
)
group_id = db.Column(
db.Integer,
db.ForeignKey('groups.id')
)
user = db.relationship('User', backref='tasks')
group = db.relationship('Group', backref='tasks')
class Group(db.Model):
""" Group of tasks used for sorting """
__tablename__ = 'groups'
id = db.Column(
db.Integer,
primary_key=True,
)
name = db.Column(
db.String(50),
nullable=False
)
user_id = db.Column(
db.Integer,
db.ForeignKey('users.id', ondelete='cascade'),
nullable=False
)
user = db.relationship('User', backref='groups')
def connect_db(app):
"""Connect this database to provided Flask app.
"""
db.app = app
db.init_app(app)