2018-03-01 20:32:02 +00:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
|
|
|
|
2016-12-08 03:50:48 +00:00
|
|
|
from django.db import models
|
2018-03-01 20:32:02 +00:00
|
|
|
from future.utils import python_2_unicode_compatible
|
2016-12-08 03:50:48 +00:00
|
|
|
|
|
|
|
|
2018-03-01 20:32:02 +00:00
|
|
|
@python_2_unicode_compatible
|
2016-12-08 03:50:48 +00:00
|
|
|
class DBFile(models.Model):
|
|
|
|
""" Model to store and access uploaded files """
|
|
|
|
|
2017-02-06 20:31:40 +00:00
|
|
|
name = models.CharField(max_length=190, unique=True)
|
2016-12-08 03:50:48 +00:00
|
|
|
|
|
|
|
# file data
|
|
|
|
content_type = models.CharField(max_length=100)
|
|
|
|
b64 = models.TextField()
|
2017-01-23 20:56:51 +00:00
|
|
|
mtime = models.DateTimeField(auto_now=True)
|
2016-12-08 03:50:48 +00:00
|
|
|
|
2018-03-01 20:32:02 +00:00
|
|
|
def __str__(self):
|
2017-01-27 20:52:02 +00:00
|
|
|
return u"{name} <{content_type}>".format(
|
|
|
|
name=self.name, content_type=self.content_type)
|
2017-01-10 16:29:28 +00:00
|
|
|
|
|
|
|
def save(self, **kwargs):
|
|
|
|
if self.content_type is None:
|
|
|
|
# If content type guessing fails,
|
|
|
|
# use octet stream as a major fallback
|
|
|
|
self.content_type = "application/octet-stream"
|
|
|
|
super(DBFile, self).save(**kwargs)
|