Don't use the original's filename as a path. Provide an open() method which return a proper file-like object.
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import uuid
|
||||||
|
|
||||||
from pytz import common_timezones
|
from pytz import common_timezones
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@@ -9,12 +11,9 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
|
|
||||||
from .runtime import shared_storage_backend
|
from .runtime import shared_storage_backend
|
||||||
|
|
||||||
SHARED_UPLOADED_FILE_PATH = 'shared_uploads'
|
|
||||||
|
|
||||||
|
|
||||||
def upload_to(instance, filename):
|
def upload_to(instance, filename):
|
||||||
instance.filename = filename
|
return 'shared-file-{}'.format(uuid.uuid4().hex)
|
||||||
return '/'.join([SHARED_UPLOADED_FILE_PATH, filename])
|
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
@@ -34,6 +33,9 @@ class SharedUploadedFile(models.Model):
|
|||||||
self.file.storage.delete(self.file.path)
|
self.file.storage.delete(self.file.path)
|
||||||
return super(SharedUploadedFile, self).delete(*args, **kwargs)
|
return super(SharedUploadedFile, self).delete(*args, **kwargs)
|
||||||
|
|
||||||
|
def open(self):
|
||||||
|
return self.file.storage.open(self.file.path)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class UserLocaleProfile(models.Model):
|
class UserLocaleProfile(models.Model):
|
||||||
|
|||||||
Reference in New Issue
Block a user