上载的pdf文件正确显示,但未显示所选的客户端,客户端将显示在下拉列表中,如果我们选择特定的客户端并上传多个pdf文件,则应显示所选的客户端和文件。
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'
class Client(models.Model):
Name = models.CharField(max_length=50, unique=True)
def __str__(self):
return self.Name
class Meta:
db_table : 'client'
class Client_Process(models.Model):
process = models.ForeignKey(Process, on_delete=models.CASCADE)
client = models.ForeignKey(Client, on_delete=models.CASCADE)
class Meta:
db_table : 'client_process'
views.py
def upload_files(request):
pdf1 = Client_files.objects.all()
print(pdf1)
client = Client.objects.all()
process = Client_Process.objects.all()
print(process)
print(client)
if request.method == 'POST':
form = Upload_files(request.POST,request.FILES)
pdf = Client_files.objects.all()
if form.is_valid():
for file in request.FILES.getlist('File_Name'):
Client_files.objects.create(File_Name=file)
return redirect('/pdf/upload/')
form.save()
else:
form = Upload_files()
return render(request,'upload_file.html',{'form':form,'pdf1':pdf1,'client':client,'process':process,})