Ticket #11716: 11716.patch
File 11716.patch, 2.9 KB (added by , 15 years ago) |
---|
-
django/db/models/fields/__init__.py
356 356 _("This value must be an integer.")) 357 357 358 358 def get_db_prep_value(self, value): 359 if value is None: 360 return None 361 return int(value) 359 return self.to_python(value) 362 360 363 361 def contribute_to_class(self, cls, name): 364 362 assert not cls._meta.has_auto_field, "A model can't have more than one AutoField." … … 693 691 class IntegerField(Field): 694 692 empty_strings_allowed = False 695 693 def get_db_prep_value(self, value): 696 if value is None: 697 return None 698 return int(value) 694 return self.to_python(value) 699 695 700 696 def get_internal_type(self): 701 697 return "IntegerField" -
tests/regressiontests/model_fields/tests.py
25 25 ImageFieldUsingFileTests, \ 26 26 TwoImageFieldTests 27 27 28 28 class AutoFieldTests(django.test.TestCase): 29 def test_to_python(self): 30 f = models.AutoField(primary_key=True) 31 self.assertEqual(f.to_python(3), 3) 32 self.assertEqual(f.to_python("3"), 3) 33 self.assertEqual(f.to_python(None), None) 34 self.assertRaises(ValidationError, f.to_python, "abc") 35 36 def test_get_db_prep_value(self): 37 f = models.AutoField(primary_key=True) 38 self.assertEqual(f.get_db_prep_value(3), 3) 39 self.assertEqual(f.get_db_prep_value("3"), 3) 40 self.assertEqual(f.get_db_prep_value(None), None) 41 self.assertRaises(ValidationError, f.get_db_prep_value, "abc") 42 29 43 class DecimalFieldTests(django.test.TestCase): 30 44 def test_to_python(self): 31 45 f = models.DecimalField(max_digits=4, decimal_places=2) … … 72 86 # This should not crash. That counts as a win for our purposes. 73 87 Foo.objects.filter(d__gte=100000000000) 74 88 89 class IntegerFieldTests(django.test.TestCase): 90 def test_to_python(self): 91 f = models.IntegerField() 92 self.assertEqual(f.to_python(3), 3) 93 self.assertEqual(f.to_python("3"), 3) 94 self.assertEqual(f.to_python(None), None) 95 self.assertRaises(ValidationError, f.to_python, "abc") 96 97 def test_get_db_prep_value(self): 98 f = models.IntegerField() 99 self.assertEqual(f.get_db_prep_value(3), 3) 100 self.assertEqual(f.get_db_prep_value("3"), 3) 101 self.assertEqual(f.get_db_prep_value(None), None) 102 self.assertRaises(ValidationError, f.get_db_prep_value, "abc") 103 75 104 class ForeignKeyTests(django.test.TestCase): 76 105 def test_callable_default(self): 77 106 """Test the use of a lazy callable for ForeignKey.default"""