I am trying to convert the data from a choicefield into an INT, but gets the error:
"int() argument must be a string, a bytes-like object or a number, not 'TypedChoiceField'"
However, I don't understand why the coerce=int, doesn't convert the data from the choicefield into an int.
My forms.py class
class ReviewForm(forms.Form):
readability_rating = forms.TypedChoiceField(
choices=[(1, 1), (2, 2), (3, 3), (4, 4), (5, 5)], coerce=int)
My views.py function
def readerpage(request, content_id):
form = ReviewForm(request.POST)
if form.is_valid():
review.readability_rating = forms.TypedChoiceField(
choices=[(1, 1), (2, 2), (3, 3), (4, 4), (5, 5)], coerce=int)
review.save()
form = ReviewForm()
return redirect('home')
My model
class Review(models.Model):
readability_rating = models.IntegerField(null=True)
Thanks for reading this