Skip to content

Commit

Permalink
Merge pull request #3 from kriberg/master
Browse files Browse the repository at this point in the history
Support for DecimalField
  • Loading branch information
af committed Mar 13, 2012
2 parents d951300 + 27c9dfa commit 5a4f2d8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions djangbone/views.py
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime import datetime
import decimal
import json import json


from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
Expand All @@ -9,14 +10,19 @@
class DjangboneJSONEncoder(json.JSONEncoder): class DjangboneJSONEncoder(json.JSONEncoder):
""" """
JSON encoder that converts additional Python types to JSON. JSON encoder that converts additional Python types to JSON.
Currently only datetime.datetime instances are supported.
""" """
def default(self, obj): 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): class BackboneAPIView(View):
Expand Down

0 comments on commit 5a4f2d8

Please sign in to comment.