Skip to content
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

use DjangoJSONEncoder on ArrayFormField to support datetime, UUID, Decimal, etc. #142

Merged
merged 3 commits into from
Feb 4, 2024

Conversation

nullcode
Copy link
Contributor

@nullcode nullcode commented Feb 2, 2024

current JSONEncoder would throw "Object of type Decimal is not JSON serializable" if you are using the libraries' ArrayField with a base_field of models.DecimalField().
This is a fix for that.

from django_jsonform.models.fields import ArrayField
example = ArrayField(models.DecimalField(decimal_places=2, max_digits=5))

@bhch
Copy link
Owner

bhch commented Feb 4, 2024

Thanks for the PR.

I think instead of writing our own encoder class, we should just use Django provided DjangoJSONEncoder. It will take care of encoding other objects as well such as datetime.

Copy link
Owner

@bhch bhch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

I think instead of writing our own encoder class, we should just use Django provided DjangoJSONEncoder. It will take care of encoding other objects as well such as datetime.

If you could update your PR with those changes, it would be great.

@nullcode nullcode changed the title fix Decimal support on ArrayFormField use DjangoJSONEncoder on ArrayFormField to support datetime, UUID, Decimal, etc. Feb 4, 2024
@nullcode
Copy link
Contributor Author

nullcode commented Feb 4, 2024

sure, makes sense @bhch , updated the PR.

@bhch bhch merged commit f3ab788 into bhch:master Feb 4, 2024
17 checks passed
@bhch
Copy link
Owner

bhch commented Feb 29, 2024

Released in v2.22.0.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants