Skip to content

Instantly share code, notes, and snippets.

@elky elky/
Created Dec 23, 2016

What would you like to do?
Django JSONField prevent Unicode sequence in Admin
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)
from django.contrib import admin
from django.contrib.postgres.fields import JSONField
from .utils import ReadableJSONFormField
class ExampleAdmin(admin.ModelAdmin):
formfield_overrides = {
JSONField: {'form_class': ReadableJSONFormField},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.