I am using django-prettyjson to format my JSONFields in the admin. My code is setup as follows:
models.py
class MyModel(models.Model):
structure = JSONField(default=dict, blank=True, null=True)
static_structure = JSONField(default=dict, blank=True, null=True, editable=False)
admin.py
class MyModelAdmin(admin.ModelAdmin):
formfield_overrides = {
JSONField: {'widget': PrettyJSONWidget }
}
def get_readonly_fields(self, request, obj=None):
if obj:
return ('static_structure')
else:
return super(MyModelAdmin, self).get_readonly_fields(request, obj)
admin.site.register(MyModel, MyModelAdmin)
In other words, one of the JSONFields is not editable and read-only. It appears on my admin panel, but its not being affected by the widget which renders the other field as formatted JSON.
Any way to fix this? Looking through plain-text JSON data is a complete drag. Thanks!