如果我有跟踪客户艺术的基本模型:
class ArtEntry(models.Model):
client = models.CharField(max_length=50, choices=CLIENT_CHOICES)
job_number = models.CharField(max_length=30, unique=False, blank=False, null=False)
filename = models.CharField(max_length=64, unique=False, blank=False, null=False)
descriptor = models.CharField(max_length=64, unique=False, blank=True, null=True)
date = models.DateField(("Date"), default=datetime.date.today)
post_type = models.CharField(max_length=64, choices=POST_CHOICES)
,此模型的最后一个字段是文件上传字段:
upload = models.FileField(upload_to='documents/*/**/***')
是否可以动态填充“upload_to”参数,以便* =输入'client'数据和** =输入'job_number'和 * ='post_type'选项?
答案 0 :(得分:1)
答案 1 :(得分:0)
一个例子;
def image_path(self, uploaded_file_name):
prefix = 'documents/'
extension = os.path.splitext(uploaded_file_name)[-1]
if self.pk != None:
return prefix + str(self.pk) + extension
else:
tmp_name = str(uuid.uuid4())
self.temp_image = prefix + tmp_name + extension
return self.temp_image
image_upload = models.ImageField(upload_to=image_path, null=True, blank=True)
你应该使用python函数。