diff -r f7a90d86bf60 django/db/models/fields/__init__.py
a
|
b
|
|
689 | 689 | _("This value must be a decimal number.")) |
690 | 690 | |
691 | 691 | def _format(self, value): |
692 | | if isinstance(value, basestring): |
| 692 | if isinstance(value, basestring) or value is None: |
693 | 693 | return value |
694 | 694 | else: |
695 | 695 | return self.format_number(value) |
diff -r f7a90d86bf60 tests/regressiontests/model_fields/tests.py
a
|
b
|
|
15 | 15 | Traceback (most recent call last): |
16 | 16 | ... |
17 | 17 | ValidationError: [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) |
| 22 | u'2.0' |
| 23 | |
| 24 | >>> f.get_db_prep_save(2.56) |
| 25 | u'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 | |
18 | 37 | """ |