Trying to overload Django 1.9 JSONField

37 views
Skip to first unread message

Benjamin Scherrey

unread,
Aug 28, 2016, 2:15:38 PM8/28/16
to Django
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: https://bpaste.net/show/52e05f5ae2a9

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?

thanx,

  -- 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!!

Tim Graham

unread,
Aug 28, 2016, 6:29:14 PM8/28/16
to Django users
Custom encoding for JSONField will be a feature in Django 1.11. See if https://github.com/django/django/pull/7071/commits/13c3e5d5a05e9c358d212d154addd703cac3bc66 and the documentation tips in that patch helps.
Reply all
Reply to author
Forward
0 new messages