-
Notifications
You must be signed in to change notification settings - Fork 86
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
Why decimal? #30
Comments
Yup all of that is true, it's not a perfect solution. I think adding an option/toggle is probably the best way to appease all parties. |
Is this still an open issue? What's the best workaround in the meanwhile? |
It is, however this will get you most of the way there: from json_field import JSONField
from json_field.fields import JSONDecoder
class Test(models.Model):
json = JSONField(decoder_kwargs={'cls':JSONDecoder, 'parse_float':float}) |
Adding those decoder_kwargs to each model field seems to be the only way to get the admin form field to save float/decimal values as numbers, rather than strings. Any way that can be made the default behavior? |
+1 on this. My application is such that it's trying to compare Decimal to float's and raising exceptions. I've specified decoder_kwargs like you say above but it's inconvenient. I'd love to see a setting I'd be willing to do the legwork and submit a pull request if you give me the go-ahead. |
My 2¢: Global settings are a very bad idea for this kind of thing - different applications that use django-json-field might want different values of the setting. Why is specifying keyword arguments inconvenient? If you dislike repeating it every time, then don't repeat it every time - just write your own wrapper:
|
I've noticed that django-json-field treats my floating point data as Decimal type. I've seen why you did it by looking at the issues history of the project on GitHub, but I think it's really inconvenient, here's why:
Could you make an option to be used in the field declaration to treat floats as floats? E.g.
f = JSONField(null=True, pure_float=True)
... or something like it?
The text was updated successfully, but these errors were encountered: