diff options
| author | Brendan MacDonell <brendan@macdonell.net> | 2012-08-06 10:42:21 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2012-08-06 10:42:21 +0200 |
| commit | ad237fb72f769bbd99b5ed6e3292bead614e1c94 (patch) | |
| tree | 87846e67a25363fe866a261726467ca774c694d7 | |
| parent | 9a3026a920286e9932401300d14f72a85ba03a43 (diff) | |
Fixed #18724 -- Fixed IntegerField validation with value 0
| -rw-r--r-- | django/db/models/fields/__init__.py | 3 | ||||
| -rw-r--r-- | tests/regressiontests/model_fields/tests.py | 4 |
2 files changed, 6 insertions, 1 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 9606b1b843..de24a24ed1 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -179,7 +179,8 @@ class Field(object): if not self.editable: # Skip validation for non-editable fields. return - if self._choices and value: + + if self._choices and value not in validators.EMPTY_VALUES: for option_key, option_value in self.choices: if isinstance(option_value, (list, tuple)): # This is an optgroup, so look inside the group for diff --git a/tests/regressiontests/model_fields/tests.py b/tests/regressiontests/model_fields/tests.py index e86159463d..7d6071accc 100644 --- a/tests/regressiontests/model_fields/tests.py +++ b/tests/regressiontests/model_fields/tests.py @@ -274,6 +274,10 @@ class ValidationTest(test.TestCase): self.assertRaises(ValidationError, f.clean, None, None) self.assertRaises(ValidationError, f.clean, '', None) + def test_integerfield_validates_zero_against_choices(self): + f = models.IntegerField(choices=((1, 1),)) + self.assertRaises(ValidationError, f.clean, '0', None) + def test_charfield_raises_error_on_empty_input(self): f = models.CharField(null=False) self.assertRaises(ValidationError, f.clean, None, None) |
