Ticket #9942: patch_django_9942.20090102.diff
File patch_django_9942.20090102.diff, 3.7 KB (added by , 16 years ago) |
---|
-
django/db/models/fields/__init__.py
658 658 def get_internal_type(self): 659 659 return "FloatField" 660 660 661 def to_python(self, value): 662 if value is None: 663 return value 664 try: 665 return float(value) 666 except (TypeError, ValueError): 667 raise exceptions.ValidationError( 668 _("This value must be a float.")) 669 661 670 def formfield(self, **kwargs): 662 671 defaults = {'form_class': forms.FloatField} 663 672 defaults.update(kwargs) -
tests/regressiontests/fixtures_regress/fixtures/sequence.json
5 5 "fields": { 6 6 "name": "Lion", 7 7 "latin_name": "Panthera leo", 8 "count": 3 8 "count": 3, 9 "weight": 1.2 9 10 } 10 11 } 11 12 ] 13 No newline at end of file -
tests/regressiontests/fixtures_regress/fixtures/animal.xml
4 4 <field type="CharField" name="name">Emu</field> 5 5 <field type="CharField" name="latin_name">Dromaius novaehollandiae</field> 6 6 <field type="IntegerField" name="count">42</field> 7 <field type="FloatField" name="weight">1.2</field> 7 8 </object> 8 9 </django-objects> 10 No newline at end of file -
tests/regressiontests/fixtures_regress/models.py
7 7 name = models.CharField(max_length=150) 8 8 latin_name = models.CharField(max_length=150) 9 9 count = models.IntegerField() 10 weight = models.FloatField() 10 11 11 12 def __unicode__(self): 12 13 return self.common_name … … 14 15 def animal_pre_save_check(signal, sender, instance, **kwargs): 15 16 "A signal that is used to check the type of data loaded from fixtures" 16 17 print 'Count = %s (%s)' % (instance.count, type(instance.count)) 18 print 'Weight = %s (%s)' % (instance.weight, type(instance.weight)) 17 19 18 20 class Plant(models.Model): 19 21 name = models.CharField(max_length=150) … … 69 71 # Create a new animal. Without a sequence reset, this new object 70 72 # will take a PK of 1 (on Postgres), and the save will fail. 71 73 # This is a regression test for ticket #3790. 72 >>> animal = Animal(name='Platypus', latin_name='Ornithorhynchus anatinus', count=2 )74 >>> animal = Animal(name='Platypus', latin_name='Ornithorhynchus anatinus', count=2, weight=2.3) 73 75 >>> animal.save() 74 76 75 77 ############################################### … … 149 151 [1, 2, 3, 4, 5, 6, 7, 8] 150 152 151 153 ############################################### 152 # Test for ticket #8298 - Field values should be coerced into the correct type153 # by the deserializer, not as part of the database write.154 # Test for tickets #8298, #9942 - Field values should be coerced into the 155 # correct type by the deserializer, not as part of the database write. 154 156 155 157 >>> models.signals.pre_save.connect(animal_pre_save_check) 156 158 >>> management.call_command('loaddata', 'animal.xml', verbosity=0) 157 159 Count = 42 (<type 'int'>) 160 Weight = 1.2 (<type 'float'>) 158 161 159 162 >>> models.signals.pre_save.disconnect(animal_pre_save_check) 160 163