Django Ошибка атрибута - у объекта нет атрибута 'get' - PullRequest
0 голосов
/ 16 марта 2020

Я пытаюсь создать форму загрузки нескольких файлов, используя фабрику 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})

...