Skip to content

Instantly share code, notes, and snippets.

@dorosch
Created March 23, 2020 07:44
Show Gist options
  • Save dorosch/d5f0b6ce58bbd74a93f16ec2c22654ba to your computer and use it in GitHub Desktop.
Save dorosch/d5f0b6ce58bbd74a93f16ec2c22654ba to your computer and use it in GitHub Desktop.
Implement django-storage with random uuid-path
import os
import uuid
from django.core.files import storage as django_storage
class LocalMediaStorage(django_storage.FileSystemStorage):
def get_available_name(self, name, max_length=None):
path, filename = os.path.split(name)
name = os.path.join(path, str(uuid.uuid4()), filename)
return super().get_available_name(name, max_length)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment