int значення в radio форму



class ReviewForm(ModelForm):
RATING_CHOICES = ((1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5'),)
rate = forms.TypedChoiceField(choices=RATING_CHOICES, \
widget=forms.RadioSelect, coerce=int)

def clean_rate(self):
if self.cleaned_data['rate'] >= 1 and self.cleaned_data['rate'] <= 5:
return self.cleaned_data['rate']
else:
raise forms.ValidationError(_("Rating error"))

class Meta:
model = Reviews
fields = ('rate', 'message', 'content_type', 'object_id')
widgets = {
'content_type' : forms.HiddenInput(),
'object_id' : forms.HiddenInput()
}

Немає коментарів: