虽然选择了多个pdf文件,但是在保存时仅保存一个文件
views.py
def pdf_upload(request):
pdf = Client_files.objects.all()
client = Client.objects.all()
process = Client_Process.objects.all()
print(process)
print(client)
if request.method == 'POST':
form = Upload_files(request.POST,request.FILES)
if form.is_valid():
form.save()
return redirect('/pdf/upload/')
else:
form = Upload_files()
return render(request,'uploadpdf.html',{'form':form,'pdf':pdf,'client':client,'process':process,})
models.py
class Client_files(models.Model):
Date = models.DateTimeField(default=datetime.now, blank=True)
client = models.ForeignKey(Client, on_delete=models.CASCADE,null=True)
client_process = models.ForeignKey(Client_Process, on_delete=models.CASCADE,null=True)
File_Name = models.FileField()
Pages = models.IntegerField(null=True)
Count = models.IntegerField(null=True)
Status = models.BooleanField(default = False)
class Meta:
db_table : 'client_files'
附加视图和模型,选择文件时我可以选择多个文件,但是上传时我只能上传一个文件
答案 0 :(得分:0)
您可以尝试这样上传多个文件:
if request.method == 'POST':
form = Upload_files(request.POST,request.FILES)
if form.is_valid():
form.save()
for file in request.FILES.getlist('File_Name'):
Client_files.objects.create (File_Name=file)
return redirect('/pdf/upload/')