defupload_to_dest(path='',human_readable_field='hrfname'):defunique_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)ifhasattr(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())returnos.path.join(path,filename)returnunique_filepath