-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
executable file
·79 lines (65 loc) · 2.62 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
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class User(db.Model):
__tablename__ = "user"
name = db.Column(db.String(100), primary_key = True, autoincrement = False)
password = db.Column(db.String(256))
def __init__(self, name, password):
self.name = name
self.password = password
class Message(db.Model):
__tablename__ = "message"
messageid = db.Column(db.String(36), primary_key = True, autoincrement = False)
senderid = db.Column(db.String(100))
receiverid = db.Column(db.String(100))
channelid = db.Column(db.String(36))
body = db.Column(db.String(100))
timestamp = db.Column(db.DateTime)
def __init__(self, messageid, senderid, receiverid, channelid, body, timestamp):
self.messageid = messageid
self.senderid = senderid
self.receiverid = receiverid
self.channelid = channelid
self.body = body
self.timestamp = timestamp
class Channel(db.Model):
__tablename__ = "channel"
channelid = db.Column(db.String(200), primary_key = True, autoincrement = False)
user1 = db.Column(db.String(100))
user2 = db.Column(db.String(100))
def __init__ (self, channelid, user1, user2):
self.channelid = channelid
self.user1 = user1
self.user2 = user2
class GroupTable(db.Model):
__tablename__ = "groupTable"
id = db.Column(db.Integer, primary_key = True)
groupname = db.Column(db.String(100))
username = db.Column(db.String(100))
def __init__(self, groupname, username):
self.groupname = groupname
self.username = username
class GroupChannel(db.Model):
__tablename__ = "groupChannel"
channelid = db.Column(db.String(100), primary_key = True, autoincrement = False)
groupname = db.Column(db.String(100))
def __init__(self, channelid, groupname):
self.channelid = channelid
self.groupname = groupname
class GroupMessage(db.Model):
__tablename__ = "groupMessage"
messageid = db.Column(db.String(100), primary_key = True, autoincrement = False)
senderid = db.Column(db.String(100))
channelid = db.Column(db.String(100))
groupname = db.Column(db.String(100))
body = db.Column(db.String(100))
timestamp = db.Column(db.DateTime)
def __init__(self, messageid, senderid, channelid, groupname, body, timestamp):
self.messageid = messageid
self.senderid = senderid
self.channelid = channelid
self.groupname = groupname
self.body = body
self.timestamp = timestamp
def as_dict(self):
return {c.name : str(getattr(self, c.name)) for c in self.__table__.columns }