Ticket #8101: 8101_boolean_fields_fix.diff
File 8101_boolean_fields_fix.diff, 1.8 KB (added by , 16 years ago) |
---|
-
django/db/models/fields/__init__.py
505 505 def get_db_prep_value(self, value): 506 506 if value is None: 507 507 return None 508 return bool(value)508 return self.to_python(value) 509 509 510 510 def get_manipulator_field_objs(self): 511 511 return [oldforms.CheckboxField] … … 1015 1015 def get_db_prep_value(self, value): 1016 1016 if value is None: 1017 1017 return None 1018 return bool(value)1018 return self.to_python(value) 1019 1019 1020 1020 def get_manipulator_field_objs(self): 1021 1021 return [oldforms.NullBooleanField] -
tests/regressiontests/model_fields/tests.py
5 5 ... except ImportError: 6 6 ... from django.utils._decimal import Decimal 7 7 8 # BooleanField 9 10 >>> f = BooleanField() 11 >>> f.to_python(True) 12 True 13 >>> f.to_python(False) 14 False 15 >>> f.to_python(u'1') 16 True 17 >>> f.to_python(u'0') 18 False 19 >>> f.to_python(None) 20 Traceback (most recent call last): 21 ... 22 ValidationError: [u'This value must be either True or False.'] 23 24 >>> f.get_db_prep_value(None) 25 >>> f.get_db_prep_value(u'1') 26 True 27 >>> f.get_db_prep_value(u'0') 28 False 29 30 # NullBooleanField 31 >>> f = NullBooleanField() 32 >>> f.to_python(True) 33 True 34 >>> f.to_python(False) 35 False 36 >>> f.to_python(u'1') 37 True 38 >>> f.to_python(u'0') 39 False 40 >>> f.to_python(None) 41 42 >>> f.get_db_prep_value(None) 43 >>> f.get_db_prep_value(u'1') 44 True 45 >>> f.get_db_prep_value(u'0') 46 False 47 8 48 # DecimalField 9 49 10 50 >>> f = DecimalField(max_digits=4, decimal_places=2)