动态上传字段参数 [英] dynamic upload field arguments
问题描述
如果我有跟踪客户端艺术的基本模型:
if I have basic model for keeping track of client art:
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)
,此模型的最后一个字段是文件上传字段:
and the last field of this model is a file upload field:
upload = models.FileField(upload_to='documents/*/**/***')
可以动态填充upload_to参数,以便* =输入'客户端'数据,** =输入'job_number'和 * ='post_t ype'选择?
is it possible to populate the "upload_to" argument dynamically, so that * = the input 'client' data and ** = the input 'job_number' and * = the 'post_type' choice?
推荐答案
当然可以。只需查看 upload_to
:
Sure. Just check the docs for upload_to
:
这也可能是一个可调用的,如函数,这将被称为
来获取上传路径,包括文件名。
This may also be a callable, such as a function, which will be called to obtain the upload path, including the filename.
检查这个答案,看一个你可以很容易地适应你的问题的例子。
Check this answer to see an example which you can easily adapt to your problem.
这篇关于动态上传字段参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!