-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodels.py
More file actions
165 lines (141 loc) · 4.07 KB
/
models.py
File metadata and controls
165 lines (141 loc) · 4.07 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
"""
Our DB model for sqlalchemy
"""
# models.py
from sqlalchemy.dialects import postgresql
from app import DB
class Posts(DB.Model):
"""
Our table for posts
"""
id = DB.Column(DB.Integer, primary_key=True)
username = DB.Column(DB.String(256))
pfp = DB.Column(DB.String(256))
music_type = DB.Column(DB.String(120))
music = DB.Column(DB.JSON)
message = DB.Column(DB.String(256))
num_likes = DB.Column(DB.Integer)
datetime = DB.Column(DB.DateTime)
def __init__(self, username, pfp, music_type, music, message, num_likes, datetime):
"""
Initializes row in Posts
"""
self.username = username
self.pfp = pfp
self.music_type = music_type
self.music = music
self.message = message
self.num_likes = num_likes
self.datetime = datetime
def __repr__(self):
"""
Display
"""
return "<Posts: %s>" % self.message
class Comments(DB.Model):
"""
Table for comments
"""
id = DB.Column(DB.Integer, primary_key=True)
username = DB.Column(DB.String(256))
text = DB.Column(DB.String(256))
post_id = DB.Column(DB.Integer)
datetime = DB.Column(DB.DateTime)
def __init__(self, username, text, post_id, datetime):
"""
Initialize row in Comments
"""
self.username = username
self.text = text
self.post_id = post_id
self.datetime = datetime
def __repr__(self):
"""
Prints comments
"""
return "<Comment name: {}\ntext:{}\npost_id: {}".format(
self.username, self.text, self.post_id)
class Users(DB.Model):
"""
Users Table
"""
username = DB.Column(DB.String(256), primary_key=True)
profile_picture = DB.Column(DB.String(256))
user_type = DB.Column(DB.String(256))
top_artists = DB.Column(postgresql.ARRAY(DB.String))
following = DB.Column(postgresql.ARRAY(DB.String))
my_likes = DB.Column(postgresql.ARRAY(DB.Integer))
def __init__(self, username, profile_picture, user_type,
top_artists, following, my_likes):
"""
Row in Users
"""
self.username = username
self.profile_picture = profile_picture
self.user_type = user_type
self.top_artists = top_artists
self.following = following
self.my_likes = my_likes
def __repr__(self):
"""
Prints Users
"""
return "<Users name: {}".format(self.username)
class Trending(DB.Model):
"""
Trending Table
"""
id = DB.Column(DB.Integer, primary_key=True)
track = DB.Column(DB.String(500))
artists = DB.Column(postgresql.ARRAY(DB.String))
def __init__(self, track, artists):
"""
Row in Trending
"""
self.track = track
self.artists = artists
def __repr__(self):
"""
Print Trending
"""
return "<Trending track: {} artists: {}>".format(
self.track, self.artists)
class ActiveUsers(DB.Model):
"""
A table of Active Users
"""
id = DB.Column(DB.Integer, primary_key=True)
user = DB.Column(DB.String(500))
serverid = DB.Column(DB.String(500))
authtoken = DB.Column(DB.String(500))
def __init__(self, user, serverid, authtoken):
"""
Row in the table
"""
self.user = user
self.serverid = serverid
self.authtoken = authtoken
def __repr__(self):
"""
Make it printable
"""
return "<ActiveUsers user: {} id: {}>".format(self.user, self.serverid)
class Likes(DB.Model):
"""
Table of likes on posts
"""
id = DB.Column(DB.Integer, primary_key=True)
username = DB.Column(DB.String(256))
post_id = DB.Column(DB.Integer())
def __init__(self, username, post_id):
"""
Row in likes
"""
self.username = username
self.post_id = post_id
def __repr__(self):
"""
print it
"""
return "<Likes username: {} post_id: {}>".format(
self.username, self.post_id)