Ticket #4485: decimal_field_nullable_r7722.diff

File decimal_field_nullable_r7722.diff, 1.2 KB (added by George Vilches, 16 years ago)

Nullable field decimal patch updated to r7722.

  • django/db/models/fields/__init__.py

    diff -r f7a90d86bf60 django/db/models/fields/__init__.py
    a b  
    689689                _("This value must be a decimal number."))
    690690
    691691    def _format(self, value):
    692         if isinstance(value, basestring):
     692        if isinstance(value, basestring) or value is None:
    693693            return value
    694694        else:
    695695            return self.format_number(value)
  • tests/regressiontests/model_fields/tests.py

    diff -r f7a90d86bf60 tests/regressiontests/model_fields/tests.py
    a b  
    1515Traceback (most recent call last):
    1616...
    1717ValidationError: [u'This value must be a decimal number.']
     18
     19>>> f = DecimalField(max_digits=5, decimal_places=1)
     20
     21>>> f.get_db_prep_save(2.0)
     22u'2.0'
     23
     24>>> f.get_db_prep_save(2.56)
     25u'2.6'
     26
     27>>> f.get_db_prep_save(None)
     28>>> f.get_db_prep_lookup('exact', 2.0)
     29[u'2.0']
     30
     31>>> f.get_db_prep_lookup('exact', 2.56)
     32[u'2.6']
     33
     34>>> f.get_db_prep_lookup('exact', None)
     35[None]
     36
    1837"""
Back to Top