-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels.py
107 lines (97 loc) · 2.53 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
from datetime import datetime
import hashlib
from db import Base
from sqlalchemy import Column, String, DateTime, ForeignKey
from sqlalchemy.sql.functions import current_timestamp
from sqlalchemy.dialects.mysql import INTEGER, BOOLEAN
class User(Base):
'''
id : 主キー
username : ユーザー名
password : パスワード
mail : メールアドレス
'''
__tablename__ = 'user'
id = Column(
'id',
INTEGER(unsigned=True),
primary_key=True,
autoincrement=True
)
username = Column(
'username',
String(256)
)
password = Column(
'password',
String(256)
)
mail = Column(
'mail',
String(256)
)
def __init__(self, username: str, password: str, mail: str):
self.username = username
self.password = hashlib.md5(password.encode()).hexdigest()
self.mail = mail
def __str__(self):
return str(self.id) + \
': username = ' + str(self.username) + \
', password = ' + self.password + \
', mail = ' + self.mail
class Task(Base):
'''
id : 主キー
user_id : 作成者(外部キー)
date : 作成日
content : 内容
deadline : 締め切り
done : タスクを終了フラグ
'''
__tablename__ = 'task'
id = Column(
'id',
INTEGER(unsigned=True),
primary_key=True,
autoincrement=True
)
user_id = Column(
'user_id',
ForeignKey('user.id')
)
date = Column(
'date',
DateTime,
default=datetime.now(),
nullable=False,
server_default=current_timestamp()
)
content = Column(
'content',
String(256)
)
deadline = Column(
'deadline',
DateTime,
default=None,
nullable=False
)
done = Column(
'done',
BOOLEAN,
default=False,
nullable=False
)
def __init__(self, user_id: int, content: str, deadline: datetime):
self.user_id = user_id
self.date = datetime.now()
self.content = content
self.deadline = deadline
self.done = False
def __str__(self):
return str(self.id) + \
': user_id = ' + str(self.user_id) + \
', date = ' + self.date.strftime('%Y/%m/%d %H:%M:%S') + \
', content = ' + self.content + \
', deadline = ' + self.deadline.strftime('%Y/%m/%d %H:%M:%S') + \
', done = ' + str(self.done)