Skip to content
Browse files

Merge pull request #3 from kriberg/master

Support for DecimalField
  • Loading branch information...
2 parents d951300 + 27c9dfa commit 5a4f2d80b7b2df183c992af40fc749ebf0c8a30a @af committed Mar 12, 2012
Showing with 10 additions and 4 deletions.
  1. +10 −4 djangbone/views.py
View
14 djangbone/views.py
@@ -1,4 +1,5 @@
import datetime
+import decimal
import json
from django.core.exceptions import ObjectDoesNotExist
@@ -9,14 +10,19 @@
class DjangboneJSONEncoder(json.JSONEncoder):
"""
JSON encoder that converts additional Python types to JSON.
-
- Currently only datetime.datetime instances are supported.
"""
def default(self, obj):
"""
- Convert datetime objects to ISO-compatible strings during json serialization.
+ Converts datetime objects to ISO-compatible strings during json serialization.
+ Converts Decimal objects to floats during json serialization.
"""
- return obj.isoformat() if isinstance(obj, datetime.datetime) else None
+ if isinstance(obj, datetime.datetime):
+ return obj.isoformat()
+ elif isinstance(obj, decimal.Decimal):
+ return float(obj)
+ else:
+ return None
+
class BackboneAPIView(View):

0 comments on commit 5a4f2d8

Please sign in to comment.
Something went wrong with that request. Please try again.