-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
40 lines (33 loc) · 966 Bytes
/
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
import os
import json
from sqlobject import SQLObject, sqlhub, connectionForURI, StringCol, BigIntCol, BoolCol
db_filename = os.path.abspath('data.db')
connection_string = 'sqlite:' + db_filename
connection = connectionForURI(connection_string)
sqlhub.processConnection = connection
class Song(SQLObject):
name = StringCol()
artist = StringCol()
art = StringCol()
url = StringCol()
added = BigIntCol()
tags = StringCol()
lyrics = StringCol()
liked = BoolCol()
def to_dict(self):
if self.tags == '':
tags = []
else:
tags = json.loads(self.tags)
return {
'id': self.id,
'name': self.name,
'artist': self.artist,
'art': self.art,
'added': self.added,
'url': self.url,
'lyrics': self.lyrics,
'tags': tags,
'liked': self.liked
}
Song.createTable(ifNotExists=True)