Skip to content

Instantly share code, notes, and snippets.

@elky
elky / example.py
Created December 23, 2016 13:50
Django JSONField prevent Unicode sequence in Admin
# utils.py
import json
from django.contrib.postgres.forms.jsonb import InvalidJSONInput, JSONField
class ReadableJSONFormField(JSONField):
def prepare_value(self, value):
if isinstance(value, InvalidJSONInput):
return value
return json.dumps(value, ensure_ascii=False, indent=4)