-
Notifications
You must be signed in to change notification settings - Fork 19
/
music.py
57 lines (48 loc) · 1.67 KB
/
music.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
#!/usr/bin/env python
# encoding: utf-8
import mongoengine
from .base import BaseMongoStorage
from config import DB_HOST, DB_PORT, DB_NAME
mongoengine.connect(DB_NAME, host=DB_HOST, port=DB_PORT)
class MusicStorage(BaseMongoStorage, mongoengine.Document):
"""store music info
key str
title str
artist str
album str
company str
public_time str
kbps str
cover file
audio file
upload_date datetime
uuid str
"""
title = mongoengine.StringField(max_length=256, default='')
artist = mongoengine.StringField(max_length=256, default='')
album = mongoengine.StringField(max_length=256, default='')
company = mongoengine.StringField(max_length=256, default='')
public_time = mongoengine.StringField(max_length=10, default='')
kbps = mongoengine.StringField(max_length=5, default='')
cover = mongoengine.FileField()
audio = mongoengine.FileField()
upload_date = mongoengine.DateTimeField()
uuid = mongoengine.StringField(unique=True)
meta = {
'ordering': ['-upload_date']
}
def __str__(self):
return 'title=%s, artist=%s, album=%s' % (self.title, self.artist, self.album)
def delete(self):
self.cover.delete()
self.audio.delete()
super(MusicStorage, self).delete()
def update(self, **kwargs):
cover = kwargs.pop('cover', None)
audio = kwargs.pop('audio', None)
if cover:
self.cover.replace(cover)
if audio:
self.audio.replace(audio)
self.save()
super(MusicStorage, self).update(**kwargs)