django 自定义FileField upload_to上传路径
def user_directory_path(instance, name):
"""
clean_data内容:
for k ,v in clean_data:
K: file
V: record1301DL00220230602全部.txt
K: name
V: record1301DL00220230602全部.txt
"""
filename = name[15:23]
# return the whole path to the file
return "{0}/{1}".format(filename, name)
class Fujian(models.Model):
name = models.CharField(max_length=32, verbose_name='文件名称')
# file = models.FileField(upload_to='%Y%m%d')
file = models.FileField(upload_to=user_directory_path)
uploaded_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.name
class Meta:
verbose_name_plural = '上传文件信息'