Ticket #14144: 14144.diff
File 14144.diff, 1.6 KB (added by , 14 years ago) |
---|
-
django/forms/models.py
1047 1047 for val in value: 1048 1048 if force_unicode(val) not in pks: 1049 1049 raise ValidationError(self.error_messages['invalid_choice'] % val) 1050 # Since this override inherited ModelChoiceField clean implementation, 1051 # we run custom validators here 1052 self.run_validators(value) 1050 1053 return qs 1051 1054 1052 1055 def prepare_value(self, value): -
tests/regressiontests/model_forms_regress/tests.py
23 23 f = forms.ModelMultipleChoiceField(queryset=Person.objects.all()) 24 24 self.assertNumQueries(1, f.clean, [1, 3, 5, 7, 9]) 25 25 26 def test_model_multiple_choice_run_validators(self): 27 """ 28 Test that ModelMultipleChoiceField run given validators (#14144). 29 """ 30 for i in range(30): 31 Person.objects.create(name="Person %s" % i) 32 33 self._validator_run = False 34 def my_validator(value): 35 self._validator_run = True 36 37 f = forms.ModelMultipleChoiceField(queryset=Person.objects.all(), 38 validators=[my_validator]) 39 f.clean([1,2]) 40 self.assertTrue(self._validator_run) 41 26 42 class TripleForm(forms.ModelForm): 27 43 class Meta: 28 44 model = Triple