2022-11-17 07:21:42 -08:00
|
|
|
import os
|
2022-12-03 13:06:55 -08:00
|
|
|
import secrets
|
2022-11-17 07:21:42 -08:00
|
|
|
|
|
|
|
from django.utils import timezone
|
|
|
|
|
|
|
|
|
|
|
|
def upload_namer(prefix, instance, filename):
|
|
|
|
"""
|
|
|
|
Names uploaded images, obscuring their original name with a random UUID.
|
|
|
|
"""
|
|
|
|
now = timezone.now()
|
|
|
|
_, old_extension = os.path.splitext(filename)
|
2022-12-03 13:06:55 -08:00
|
|
|
new_filename = secrets.token_urlsafe(20)
|
2022-11-17 07:21:42 -08:00
|
|
|
return f"{prefix}/{now.year}/{now.month}/{now.day}/{new_filename}{old_extension}"
|