shimatta-kenkyusho/shimatta_kenkyusho/shimatta_modules/RandomFileName.py

13 lines
413 B
Python
Raw Normal View History

2021-08-07 17:37:36 +02:00
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)