dynamic FilePathField question

后端 未结 4 1754
臣服心动
臣服心动 2020-12-18 15:48

I have a model where the location of pdf directory I\'m pointing to with my FilePathField is based on the \"client\" and \"job_number\" fields.

class CCEntry         


        
4条回答
  •  攒了一身酷
    2020-12-18 16:10

    try to set the path value as callable function

    def get_path(instance, filename):
        return "site_media/jobs/%s_%s/%s" % (instance.client, instance.job_number, filename)
    
    
    class CCEntry(models.Model):
        ....
        pdf = models.FilePathField(path=get_path, match=".*\.pdf$", recursive=True)
    

    but I'm not sure if this works, I didn't test it.

提交回复
热议问题