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
334 stars 34 forks source link

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

Closed nullcode closed 8 months ago

nullcode commented 8 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 8 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 8 months ago

sure, makes sense @bhch , updated the PR.

bhch commented 7 months ago

Released in v2.22.0.

Thank you.