This came up in a ticket a couple days ago: 
https://code.djangoproject.com/ticket/25995

On Tuesday, January 5, 2016 at 11:18:01 AM UTC-5, Aymeric Augustin wrote:
>
> Hello, 
>
> I’m using the JSONField provided by django.contrib.postgres for logging 
> arbitrary data to PostgreSQL. 
>
> For this use case, I’d like my data to be JSON serialized with as little 
> fuss as possible. Unfortunately lots of things (dates, datetimes, decimals, 
> etc.) aren’t natively JSON-serializable and django.contrib.postgres doesn’t 
> seem to provide a way to override the serializer. 
>
> I can wire Django’s JSON encoder, which provides reasonable encoding rules 
> for all data types I need, by monkey-patching JSONField: 
>
>
> # Monkey-patch django.contrib.postgres to use a smarter JSON serializer. 
>
> import json 
>
> from django.contrib.postgres.fields import jsonb 
> from django.core.serializers.json import DjangoJSONEncoder 
>
>
> class DjangoJson(jsonb.Json): 
>
>     def dumps(self, obj): 
>         return json.dumps(obj, cls=DjangoJSONEncoder) 
>
>
> jsonb.Json = DjangoJson 
>
>
> Is this a common problem? Should JSONField accept additional kwargs to 
> customize the encoder and the decoder? 
>
> Best regards, 
>
> -- 
> Aymeric. 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/191e3419-dc33-43c2-8653-a43494774c93%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to