Skip to content

Add a Django settings override for parse_float #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion json_field/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.utils import simplejson as json

from django.db import models
from django.conf import settings
from django.core import exceptions
from django.utils.translation import ugettext_lazy as _
from django.core.exceptions import ImproperlyConfigured
Expand All @@ -27,6 +28,9 @@
except AttributeError:
JSON_DECODE_ERROR = ValueError # other


JSON_FIELD_PARSE_FLOAT = getattr(settings, 'JSON_FIELD_PARSE_FLOAT', decimal.Decimal)

TIME_FMT = r'\d{2}:\d{2}:\d{2}(\.\d+)?'
DATE_FMT = r'\d{4}-\d{2}-\d{2}'
TIMEZONE_FMT = r'(\+|\-)\d{2}:\d{2}'
Expand Down Expand Up @@ -155,7 +159,7 @@ def __init__(self, *args, **kwargs):
if not encoder_kwargs and encoder:
encoder_kwargs.update({'cls':encoder})
if not decoder_kwargs and decoder:
decoder_kwargs.update({'cls':decoder, 'parse_float':decimal.Decimal})
decoder_kwargs.update({'cls':decoder, 'parse_float': JSON_FIELD_PARSE_FLOAT})
self.encoder_kwargs = encoder_kwargs
self.decoder_kwargs = decoder_kwargs

Expand Down