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 = '上传文件信息'
标签:return,name,自定义,models,upload,django,file,FileField From: https://www.cnblogs.com/vPYer/p/17455798.html