Start content
This commit is contained in:
13
shimatta_kenkyusho/shimatta_modules/RandomFileName.py
Normal file
13
shimatta_kenkyusho/shimatta_modules/RandomFileName.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import os
|
||||
import uuid
|
||||
from django.utils.deconstruct import deconstructible
|
||||
|
||||
# Ref: https://stackoverflow.com/questions/2673647/enforce-unique-upload-file-names-using-django
|
||||
@deconstructible
|
||||
class RandomFileName(object):
|
||||
def __init__(self, path):
|
||||
self.path = os.path.join(path, "%s%s")
|
||||
|
||||
def __call__(self, _, filename):
|
||||
extension = os.path.splitext(filename)[1]
|
||||
return self.path % (uuid.uuid4(), extension)
|
Reference in New Issue
Block a user