如何在django中上传PDF文件

时间:2016-12-13 13:53:33

标签: django-media

model 
 class CustomerInfo(models.Model):
   customer_name = models.CharField(max_length=50)
   customer_letter= models.FileField(upload_to='/media/',null= True, blank=model 
 class CustomerInfo(models.Model):
   customer_name = models.CharField(max_length=50)
   customer_letter= models.FileField(upload_to='/media/',null=True,blank=         True)
   representative_name = models.CharField(max_length=50)
   representative_letter = models.FileField(upload_to='/media/', null=True, blank=True)
   ministry_approval = models.FileField(upload_to='/media/', null=True, blank=True)
   date = models.DateField()

   def __str__(self):
     return self.customer_name + ' - ' + self.customer_letter + ' - ' +    self.represntative_name + ' - ' + self.representative_letter + ' - ' + self.ministry_approval + ' - ' + self.date

def custmoer(request):
if request.method == 'POST':
    form = CustomerForm(request.POST, request.FILES)
    if form.is_valid():
        form.save()
        return HttpResponseRedirect('/login/custmoer/')
    else:
        return HttpResponseRedirect('/login')
else:
    form= CustomerForm()
    return render(request, "custmoer.html", {'form':form})   

form.py

class CustomerForm(forms.ModelForm):
   class Meta:
      model = CustomerInfo
      fields = ('customer_name', 'customer_letter', 'representative_name',    'representative_letter', 'ministry_approval', 'date')

0 个答案:

没有答案