问题
Uploaded pdf file is showing correctly but selected client is not showing,Client will displayed in dropdown,if we select particular client and upload multiple pdf files,the selected client and files should display.
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,})
来源:https://stackoverflow.com/questions/57720832/multiple-pdf-file-should-upload-along-with-pdf-file-selected-client-and-process