id,summary,reporter,owner,description,type,status,component,version,severity,resolution,keywords,cc,stage,has_patch,needs_docs,needs_tests,needs_better_patch,easy,ui_ux 5327,ModelChoiceField and ChoiceField clean methods behave differently,danielrubio,Philippe Raoult,"Using both !ChoiceField and !ModelChoiceField, I discovered a bug in !ChoiceField clean method ( or a discrepancy in behaviour) !ModelChoiceField seems to be working as expected, when I call the clean method in a template like so: form.clean.city , I get the city name(e.g New York), or what would be string inside the tag This behaviour is different if the values are inside a !ChoiceField, if I use the following in the template: form.clean.city, I get the city id (e.g 5 ), not the expected string or behaviour as using !ModelChoiceField. [NOTE: Not calling the clean field, in either !ChoiceField or !ModelChoiceField works identcally, generating a select list ] I modified the fields.py file in django/newforms, the clean method on the !ChoiceField class[line 466], would now read: {{{ #!python def clean(self, value): """""" Validates that the input is in self.choices. """""" value = super(ChoiceField, self).clean(value) if value in EMPTY_VALUES: value = u'' value = smart_unicode(value) if value == u'': return value valid_values = set([smart_unicode(k) for k, v in self.choices]) if value not in valid_values: raise ValidationError(ugettext(u'Select a valid choice. That choice is not one of the available choices.')) else: value = self._choices[int(value)][1] return value }}} Only modification is the 'else' at the end, which would assign the value to the actual string. ",,closed,Documentation,dev,,fixed,ChoiceField clean method id,,Accepted,1,0,0,0,0,0