Home > OS >  How can I fix 'IntegerField' object has no attribute 'is_hidden'?
How can I fix 'IntegerField' object has no attribute 'is_hidden'?

Time:07-06

Form kept working well till before adding this('product_price':forms.IntegerField(widget=forms.FileInput(attrs={'class': 'form-control'}))). Where did the actual problem occur? How can I fix this bellow error?

forms.py:

class add_product_info(forms.ModelForm):
    class Meta:
        model = Products
        fields = ('product_title','product_price')

        widgets = {
            'product_title':forms.TextInput(attrs={'class':'form-control'}),
     
            'product_price':forms.IntegerField(widget=forms.FileInput(attrs={'class': 'form-control'}))
 
        }

template:

<form action="" method="POST"  style="font-size: 13px;" novalidate="" autocomplete="off" enctype="multipart/form-data">
    {% csrf_token %}

    {{ form.as_p }}

    <div >
        <button type="submit"  style="font-size: 13px;">Add</button>
    </div>

</form>

Error:

AttributeError at /add_product/
'IntegerField' object has no attribute 'is_hidden'
Request Method: GET
Request URL:    http://127.0.0.1:8000/add_product/
Django Version: 4.0.4
Exception Type: AttributeError
Exception Value:    
'IntegerField' object has no attribute 'is_hidden'
Exception Location: D:\1_WebDevelopment\17_Ecomerce Website\ecomerce site\env\lib\site-packages\django\forms\boundfield.py, line 214, in is_hidden
Python Executable:  D:\1_WebDevelopment\17_Ecomerce Website\ecomerce site\env\Scripts\python.exe
Python Version: 3.9.5
Python Path:    
['D:\\1_WebDevelopment\\17_Ecomerce Website\\ecomerce site',
 'c:\\users\\dcl\\appdata\\local\\programs\\python\\python39\\python39.zip',
 'c:\\users\\dcl\\appdata\\local\\programs\\python\\python39\\DLLs',
 'c:\\users\\dcl\\appdata\\local\\programs\\python\\python39\\lib',
 'c:\\users\\dcl\\appdata\\local\\programs\\python\\python39',
 'D:\\1_WebDevelopment\\17_Ecomerce Website\\ecomerce site\\env',
 'D:\\1_WebDevelopment\\17_Ecomerce Website\\ecomerce '
 'site\\env\\lib\\site-packages']
Server time:    Tue, 05 Jul 2022 17:47:30  0000

CodePudding user response:

First of all, you are using a form field instead of a widget. Change the product_price widget like this:

forms.NumberInput(attrs={'class': 'form-control'})

Check out the documentation

  • Related