Django属性错误-对象没有属性“获取”

时间:2020-03-16 15:56:36

标签: django inline-formset

我正在尝试使用inlineformset工厂创建多个文件上传表单。我遵循了https://docs.djangoproject.com/en/3.0/topics/forms/modelforms/#django.forms.models.BaseInlineFormSet中定义的过程。

我正在追随错误。

附加了views.py和model.py文件。

请帮助。

Error:
Request Method: GET
Request URL:    http://127.0.0.1:8000/tagging/UploadMultipleFile/1/
Django Version: 3.0.2
Exception Type: AttributeError
Exception Value:    
'UploadMultiFile' object has no attribute 'get'
Exception Location: 
Python Version: 3.8.1

#MODELS.PY
class UploadInputFile(models.Model):
    process=models.ForeignKey(Process,blank=False,on_delete=models.CASCADE,related_name="inputfile")
    inputfilepath=models.FileField(upload_to=user_directory_path, null=True)
    inputfilename=models.CharField(max_length=300,blank=True)
    multiplefile=models.BooleanField(blank=True,default=False)
    date_uploaded = models.DateTimeField(auto_now=True)

    def __str__(self):
        return(self.process.process_name)

    def get_absolute_url(self):
        return reverse("tagging:tagginghome")

class UploadMultiFile(models.Model):
    process=models.ForeignKey(Process,blank=False,on_delete=models.CASCADE,related_name="process")
    batch=models.ForeignKey(UploadInputFile,blank=False,on_delete=models.CASCADE,related_name="multiplefiles")
    inputfilepath=models.FileField(upload_to=user_directory_path, null=True)
    inputfilename=models.CharField(max_length=300,blank=True)
    date_uploaded = models.DateTimeField(auto_now=True)

    def __str__(self):
        return(self.batch_id.process_id.process_name)

    def get_absolute_url(self):
        return reverse("tagging:tagginghome")
# VIEWS.PY 
# upload Multiple files
def UploadMultipleFile(request,batchid):
    batchid=int(batchid)
    pk=batchid
    getProcessAndBatch=UploadInputFile.objects.all().values().get(id=batchid)
    MultiFileUploadFormSet = inlineformset_factory(UploadInputFile,UploadMultiFile,fk_name='batch',fields=('inputfilepath','inputfilename'))
    if request.method=="POST":
        formset= MultiFileUploadFormSet(request.POST,request.FILES,instance=getProcessAndBatch)
        if formset.is_valid():
            formset.save()
    else:
        formset= MultiFileUploadFormSet(instance=getProcessAndBatch)

    return render(request,"tagging/UploadInputFile_Form.html",{'pk':pk,'formset':formset})

0 个答案:

没有答案