def serialize_file(instance, file_attr='file', thumbnail_attr='artwork'):
obj = getattr(instance, file_attr)
thumbnail = getattr(instance, thumbnail_attr)
if thumbnail:
thumbnail_url = thumbnail.url
else:
thumbnail_url = static('box/images/NoArtwork_Black.png')
return {
'url': obj.url,
'name': order_name(obj.name),
'type': mimetypes.guess_type(obj.path)[0],
'thumbnailUrl': thumbnail_url,
'size': obj.size,
'deleteUrl': reverse('box:song-delete', kwargs={'username': instance.user.username, 'slug': instance.slug}),
'deleteType': 'DELETE',
}
评论列表
文章目录