Django

Code

Show
Ignore:
Timestamp:
08/24/08 03:12:13 (3 months ago)
Author:
russellm
Message:

Fixed #8298: Added a to_python method for integer fields. This ensures that the data from deserialized instances is of correct type prior to saving. Thanks to Andrew Badr for the report.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/tests/regressiontests/fixtures_regress/fixtures/sequence.json

    r4937 r8515  
    55        "fields": { 
    66            "name": "Lion",  
    7             "latin_name": "Panthera leo" 
     7            "latin_name": "Panthera leo", 
     8            "count": 3 
    89        } 
    910    } 
  • django/trunk/tests/regressiontests/fixtures_regress/models.py

    r7803 r8515  
    77    name = models.CharField(max_length=150) 
    88    latin_name = models.CharField(max_length=150) 
    9  
     9    count = models.IntegerField() 
     10     
    1011    def __unicode__(self): 
    1112        return self.common_name 
     13 
     14def animal_pre_save_check(signal, sender, instance, **kwargs): 
     15    "A signal that is used to check the type of data loaded from fixtures" 
     16    print 'Count = %s (%s)' % (instance.count, type(instance.count)) 
    1217 
    1318class Plant(models.Model): 
     
    6570# will take a PK of 1 (on Postgres), and the save will fail. 
    6671# This is a regression test for ticket #3790. 
    67 >>> animal = Animal(name='Platypus', latin_name='Ornithorhynchus anatinus'
     72>>> animal = Animal(name='Platypus', latin_name='Ornithorhynchus anatinus', count=2
    6873>>> animal.save() 
    6974 
     
    135140[1, 2, 3, 4, 5, 6, 7, 8] 
    136141 
     142############################################### 
     143# Test for ticket #8298 - Field values should be coerced into the correct type 
     144# by the deserializer, not as part of the database write. 
     145 
     146>>> models.signals.pre_save.connect(animal_pre_save_check) 
     147>>> management.call_command('loaddata', 'animal.xml', verbosity=0) 
     148Count = 42 (<type 'int'>) 
     149 
     150>>> models.signals.pre_save.disconnect(animal_pre_save_check) 
     151 
    137152"""}