Django insert:这个错误是什么意思



你能告诉我,这个错误是什么意思:

int(( 参数必须是字符串、类似字节的对象或数字,而不是 'DeferredAttribute'

回溯 说:

异常类型:/banque 处的类型错误 异常值:int(( 参数 必须是字符串、类似字节的对象或数字,而不是 "递延属性">

我想这个错误是一个保存错误:以下是我的观点:

class BanqueViews(FormView):
def get(self, request,*args,**kwargs):
    #form=SubmitUrlForm()
    if request.user.is_active :
        current_user = request.user
        #form=FormBanque()
        form1=banqueInfo()
        form2=AjoutBanque()
        formset = BanqueFormSet()
        context={"formset":formset,"current_user":current_user,"form2":form2,"form1":form1}
        return render(request,"appOne/banquemineFormsPy.html", context)
def post(self,request,*args,**kwargs):
    current_user = request.user.id
    if request.method == "POST":
        p=int(request.POST['numpiece'])
        print(p)
        formset = BanqueFormSet(request.POST)
        form1=banqueInfo(request.POST,request.FILES);
        nom=request.POST['banque_name']
        rib=request.POST['banque_rib']
        if form1.is_valid():
            tmp=banque.objects.get(nom=nom,rib=rib)# bank name+rib should be unique
            print(tmp)
            bq=releve_bancaire(id_banque_id=tmp.id) # 
            bq.save()
            for f in formset:
                if f.is_valid():
                    cln=f.cleaned_data
                    id_fac=facture
                    tier="";
                    montantcred=f.cleaned_data.get('montantcred')
                    montantdeb=f.cleaned_data.get('montantdeb')
                    typeTiers=f.cleaned_data.get('typeTiers')
                    if typeTiers=="Client":
                        id_tier=client.objects.get(nom=cln.get('tiers'))
                        tier=id_tier.nom
                        id_fac=facture.objects.get(numfac=cln.get('numfacture').numfac,id_client_id=id_tier.id,type_fact="vente")
                    elif typeTiers=="Fournisseur":
                        id_tier=fournisseur.objects.get(nom=cln.get('tiers'))
                        #print(id_tier.id)
                        tier=id_tier.nom
                        id_fac=facture.objects.get(numfac=cln.get('numfacture').numfac,id_fournisseur_id=id_tier.id,type_fact="achat")
                    else:
                        tier=cln.get('tiers')
                        print(tier)
                    if montantdeb!=None and montantcred==None :
                        print("debitnot null")
                        s=False 
                    elif montantcred!=None and montantdeb==None :
                        print("credit not null")
                        s=True
                    b=operation_Bancaire(id_releve=bq,id_facture=id_fac.id,montantdeb=f.cleaned_data.get('montantdeb'),montantcred=f.cleaned_data.get('montantcred'),sens_operation=s,type_tiers=f.cleaned_data.get('typeTiers'),tiers=tier,date_operation=f.cleaned_data.get('dateOperation'),designation=f.cleaned_data.get("designation"))
                    b.save()
                    print('type de facture')
                    print(type(id_fac.type_fact))
                else: 
                    print("nooooott")
        else :
            print("form1 not valid")
    else:
        formset = forms.BanqueFormSet(request.POST or None) 
    context={"formset":formset,"form1":form1}
    return render(request,"appOne/banquemineFormsPy.html",context)

从我所看到的 tier变量是问题所在。 但不知道确切的问题是什么。

我意识到问题出在哪里。 如果 if 条件不存在,id_fac可以是 null facture 对象,因此不会将其插入id_facture字段中。

最新更新