I have the following code to rename my files when loading in django admin (in models.py)
def get_file_path(instance, filename):
ext = filename.split('.')[-1]
filename = "%s.%s" % (uuid.uuid4(), ext)
return os.path.join('directory/', filename)
class Archivo(models.Model):
archivo = models.FileField(upload_to = get_file_path)
This works for me, but I want to dynamically transfer the directory, something like this:
def get_file_path(instance, filename, directory_string_var):
ext = filename.split('.')[-1]
filename = "%s.%s" % (uuid.uuid4(), ext)
return os.path.join(directory_string_var, filename)
If I do this, I cannot pass the directory parameter (variable) to the method in the upload_to option of the "archivo" field.
eos87 source
share