JavaScript
x
2
1
TypeError: __init__() got an unexpected keyword argument 'choices'
2
forms.py
JavaScript
1
15
15
1
class StudentMarksheetform2(forms.Form):
2
subject_code=(
3
(1,'CS101'),
4
(2,'CS102'),
5
(3,'CS103'),
6
(4,'CS104'),
7
(5,'CS105'),
8
(6,'CS106')
9
)
10
code_title=forms.IntegerField(choices=subject_code,default='1')
11
12
class Meta():
13
model=StudentMarksheetdata2
14
fields=['code_title']
15
Advertisement
Answer
This is a form. A form deals with interacting with the user. An IntegerField
of forms
has no choices
. After all the IntegerField
of models deals with how we store data in the database.
You can use a TypedChoiceField
[Django-doc] for this:
JavaScript
1
15
15
1
class StudentMarksheetform2(forms.Form):
2
SUBJECT_CODE = (
3
(1,'CS101'),
4
(2,'CS102'),
5
(3,'CS103'),
6
(4,'CS104'),
7
(5,'CS105'),
8
(6,'CS106')
9
)
10
11
code_title=forms.TypedChoiceField(choices=SUBJECT_CODE, coerce=int, initial=1)
12
13
class Meta:
14
model=StudentMarksheetdata2
15
fields=['code_title']