__init __()需要4个参数(给定1个)

时间:2016-08-16 09:18:42

标签: python django

form.py

class InvoiceForm(ModelForm,):

    def __init__(self,em,first,last):
        self.email=em
        self.first=first
        self.last=last
        super(InvoiceForm,self).__init__(self,em,first,last)
        self.fields['email']=forms.ChoiceField(choices=[x.email for x in AuthUser.objects.filter(email=em)])
        self.fields['first']=forms.ChoiceField(choices=[x.first_name for x in AuthUser.objects.filter(first_name=first)])
        self.fields['last']=forms.ChoiceField(choices=[x.last_name for x in AuthUser.objects.filter(last_name=last)]) 
    total_credits_ordered=forms.IntegerField(label=mark_safe('<br/> total_credits_ordered'))
    total_mobile_cr_ordered=forms.IntegerField(label=mark_safe('<br/> total_mobile_cr_ordered'))
    total_cloud_cr_ordered=forms.IntegerField(label=mark_safe('<br/> total_cloud_cr_ordered'))
    invoice_currency=forms.CharField(label=mark_safe('<br/> invoice_currency'),max_length=100)
    invoice_currency_code=forms.IntegerField(label=mark_safe('<br/>invoice_currency_code '))
    invoice_country=forms.CharField(label=mark_safe('<br/> invoice_country'),max_length=100)
    invoice_note=forms.CharField(label=mark_safe('<br/> invoice_note'),max_length=100)


    class Meta:
        model=Invoices
        fields=['total_credits_ordered','total_mobile_cr_ordered','total_cloud_cr_ordered','invoice_currency','invoice_currency_code','invoice_country','invoice_note']

views.py

def test(request):
    from app.tests import model_tests
    m = model_tests()
    print "assf"


    try:

        if request.method=="POST":
            print "sff"
            m.create_user_types()
            cform=CustomerForm(request.POST)
            if cform.is_valid():
                em=cform.cleaned_data['email']
                username=email
                password = cform.cleaned_data['password']
                first=cform.cleaned_data['first']
                last=cform.cleaned_data['last']  
                companyname=cform.cleaned_data['company_name']
                companyaddr=cform.cleaned_data['company_addr']
                companystate=cform.cleaned_data['company_state']
                companycountry=cform.cleaned_data['company_country']
                id=m.create_customer(username,email,password,first,last,companyname,companyaddr,companystate,companycountry) 
                print "SFsfg"
                iform=InvoiceForm(email,first,last)
                print "ggg"
                if iform.is_valid():
                    tco=iform.cleaned_data['total_credits_ordered']
                    tmco=iform.cleaned_data['total_mobile_cr_ordered']
                    tcco=iform.cleaned_data['total_cloud_cr_ordered']
                    ic=iform.cleaned_data['invoice_currency']
                    icc=iform.cleaned_data['invoice_currency_code']
                    c=iform.cleaned_data['invoice_country']
                    inote=iform.cleaned_data['invoice_note']
                    id_i=m.create_invoices(id,tco,tmco,tcco,ic,icc,c,inote) 
                    pform=PaymentForm()
                    print "dsf"
                    pform=PaymentForm(request.POST)
                    if pform.is_valid():            
                        tpm=pform.cleaned_data['total_payment_made']
                        ps=pform.cleaned_data['payment_status']
                        pt=pform.cleaned_data['payment_type']
                        m.create_payment(id_i,tpm,ps,pt)    
                        return HttpResponse("test successful") 
        else:
            print "d"
            cform=CustomerForm()
            iform=InvoiceForm() 
            pform=PaymentForm()                                      
        return render(request, 'test.html', {'cform': cform,'iform':iform,'pform':pform})
    except Exception as e:
        return HttpResponse("Exception : %s" %(e))
    return HttpResponse("Tests Successfull...")  

显示: Exception : __init__() takes exactly 4 arguments (1 given)

但我已将参数传递给表单。

1 个答案:

答案 0 :(得分:1)

我们在问题中没有堆栈跟踪,但问题可能在这里:

***Watch has conflicting provisioning settings. ***Watch is automatically signed for development, but a conflicting code signing identity iPhone Distribution has been manually specified. Set the code signing identity value to "iPhone Developer" in the build settings editor, or switch to manual signing in the project editor.
Code signing is required for product type 'WatchKit App' in SDK 'watchOS 3.0'

在这里,您无需传递任何参数即可创建对象。由于实例本身总是被传递,因此消息表明它错过了else: print "d" cform=CustomerForm() iform=InvoiceForm() pform=PaymentForm()

的其他参数

我建议你删除em,first,last部分之后的所有内容,因为它没有任何用处,或者是这样的警告,以避免无声错误:

else