Данные формы не сохраняются в базе данных. В чем проблема?

Эта форма работает отлично,

class FeedBackForm(forms.Form):
        feedBACK = forms.CharField(widget=forms.Textarea, required=True)  

Но эта форма не сработала

class FeedBackForm(forms.Form):
    feedBACK = forms.CharField(widget=forms.Textarea, required=True)     
    rating = forms.CharField(widget=forms.IntegerField, required=True)

Выдает ошибку. Где возникла проблема? Я проверил документацию, но никакой подсказки не нашел.

AttributeError at /quick_view/11/
'IntegerField' object has no attribute 'value_from_datadict'
Request Method: POST
Request URL:    http://127.0.0.1:8000/quick_view/11/
Django Version: 4.0.4
Exception Type: AttributeError
Exception Value:    
'IntegerField' object has no attribute 'value_from_datadict'
Exception Location: D:\1_WebDevelopment\17_Ecomerce Website\ecomerce site\env\lib\site-packages\django\forms\forms.py, line 224, in _widget_data_value
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:    Wed, 13 Jul 2022 10:41:38 +0000

Поле IntegerField [Django-doc] - это форма поле, а не виджет. Вы указываете поле как:

class FeedBackForm(forms.Form):
    feedBACK = forms.CharField(widget=forms.Textarea)     
    rating = forms.IntegerField()

Note: By default, a form field has required=True [Django-doc], hence you do not need to mark fields as required.

Вернуться на верх