Answer the question
In order to leave comments, you need to log in
How to change filename on upload in Django?
How can I change the file name when uploading in Django to my own, preferably a UUID?
Answer the question
In order to leave comments, you need to log in
from os.path import splitext
from uuid import uuid4
from django.core.files.storage import FileSystemStorage
class UUIDFileStorage(FileSystemStorage):
def get_available_name(self, name, max_length=None):
_, ext = path.splitext(name)
return uuid4().hex + ext
class SomeModel(models.Model):
some_filed = models.ImageField('Какое-то изображение', upload_to='someimages', storage=UUIDFileStorage())
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question