def upload_to_dest(path='', human_readable_field='hrfname'):
def unique_filepath(instance, filename):
"""Generate random unique filename or use name
from `human_readable_field` if it's available and not empty"""
fname, ext = os.path.splitext(filename)
if hasattr(instance, human_readable_field) and \
getattr(instance, human_readable_field) and \
getattr(instance, human_readable_field) != '':
fname_chunk = getattr(instance, human_readable_field)
else:
fname_chunk = uuid.uuid4()
filename = "%s%s" % (fname_chunk, ext.lower())
return os.path.join(path, filename)
return unique_filepath
Comments
Change this:
to:
#