bhch / django-jsonform

A better, user-friendly JSON editing form field for Django admin. Also supports Postgres ArrayField.
https://django-jsonform.rtfd.io
BSD 3-Clause "New" or "Revised" License
352 stars 34 forks source link

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

Closed nullcode closed 9 months ago

nullcode commented 10 months ago

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 commented 9 months ago

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.

nullcode commented 9 months ago

sure, makes sense @bhch , updated the PR.

bhch commented 9 months ago

Released in v2.22.0.

Thank you.