Sunday, August 28, 2016

Trying to overload Django 1.9 JSONField

I have an application where we've upgraded from Django 1.7 to 1.9 that makes extensive use of the new Postgres JSONField type. Now that JSONField is native to Django I'm trying to get it to work with our existing code base. We have a class that won't automatically serialize to json so I've extended the JSONField class with a new JSONSerializedField which basically attempts to call to_json() and from_json() methods on objects if it can.

Here's the code:

By overloading get_prep_value() I've been able to handle the python->json conversion. I'm having trouble figuring out what I need to overload to handle the json->python conversion, however. Overloading to_python() doesn't seem to work as my method is never called. How can I achieve what my to_python method is trying to accomplish with the new JSONField?


  -- Ben Scherrey

Chief Systems Architect Proteus Technologies

This email intended solely for those who have received it. If you have received this email by accident - well lucky you!!

You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment