Ticket #12539: patch_and_test.diff
File patch_and_test.diff, 3.0 KB (added by , 15 years ago) |
---|
-
django/db/models/fields/__init__.py
480 480 Field.__init__(self, *args, **kwargs) 481 481 482 482 def to_python(self, value): 483 if value i s None:484 return value483 if value in validators.EMPTY_VALUES: 484 return None 485 485 try: 486 486 return int(value) 487 487 except (TypeError, ValueError): … … 609 609 return "DateField" 610 610 611 611 def to_python(self, value): 612 if value i s None:613 return value612 if value in validators.EMPTY_VALUES: 613 return None 614 614 if isinstance(value, datetime.datetime): 615 615 return value.date() 616 616 if isinstance(value, datetime.date): … … 684 684 return "DateTimeField" 685 685 686 686 def to_python(self, value): 687 if value i s None:688 return value687 if value in validators.EMPTY_VALUES: 688 return None 689 689 if isinstance(value, datetime.datetime): 690 690 return value 691 691 if isinstance(value, datetime.date): … … 756 756 return "DecimalField" 757 757 758 758 def to_python(self, value): 759 if value i s None:760 return value759 if value in validators.EMPTY_VALUES: 760 return None 761 761 try: 762 762 return decimal.Decimal(value) 763 763 except decimal.InvalidOperation: … … 844 844 return "FloatField" 845 845 846 846 def to_python(self, value): 847 if value i s None:848 return value847 if value in validators.EMPTY_VALUES: 848 return None 849 849 try: 850 850 return float(value) 851 851 except (TypeError, ValueError): … … 872 872 return "IntegerField" 873 873 874 874 def to_python(self, value): 875 if value i s None:876 return value875 if value in validators.EMPTY_VALUES: 876 return None 877 877 try: 878 878 return int(value) 879 879 except (TypeError, ValueError): … … 1028 1028 return "TimeField" 1029 1029 1030 1030 def to_python(self, value): 1031 if value i s None:1031 if value in validators.EMPTY_VALUES: 1032 1032 return None 1033 1033 if isinstance(value, datetime.time): 1034 1034 return value -
tests/regressiontests/forms/models.py
73 73 >>> f.is_valid() 74 74 False 75 75 76 # BoundaryForm with localflavor form field 77 >>> from django.contrib.localflavor.at.forms import ATZipCodeField 78 >>> class BoundaryForm(ModelForm): 79 ... positive_integer = ATZipCodeField(required=False) 80 ... class Meta: 81 ... model = BoundaryModel 82 >>> f = BoundaryForm({}) 83 >>> f.full_clean() 84 >>> f.errors 85 {} 86 76 87 # Formfield initial values ######## 77 88 If the model has default values for some fields, they are used as the formfield 78 89 initial values.