|
5 | 5 | except ImportError:
|
6 | 6 | import json
|
7 | 7 |
|
| 8 | +from decimal import Decimal |
| 9 | + |
8 | 10 | import django
|
9 | 11 | from django.db import models, connection
|
10 | 12 | from django.utils import six
|
@@ -79,15 +81,16 @@ def update(self, *args, **kwargs):
|
79 | 81 |
|
80 | 82 | def ensure_acceptable_value(self, value):
|
81 | 83 | """
|
82 |
| - - ensure booleans, integers, floats, lists and dicts are converted to string |
| 84 | + - ensure booleans, integers, floats, Decimals, lists and dicts are |
| 85 | + converted to string |
83 | 86 | - convert True and False objects to "true" and "false" so they can be
|
84 | 87 | decoded back with the json library if needed
|
85 | 88 | - convert lists and dictionaries to json formatted strings
|
86 | 89 | - leave alone all other objects because they might be representation of django models
|
87 | 90 | """
|
88 | 91 | if isinstance(value, bool):
|
89 | 92 | return force_text(value).lower()
|
90 |
| - elif isinstance(value, int) or isinstance(value, float): |
| 93 | + elif isinstance(value, (int, float, Decimal)): |
91 | 94 | return force_text(value)
|
92 | 95 | elif isinstance(value, list) or isinstance(value, dict):
|
93 | 96 | return force_text(json.dumps(value))
|
|
0 commit comments