Closed seunghokimj closed 6 years ago
Instead of using readonly_fields, use the disabled
form field attribute, introduced in Django 1.9. See https://docs.djangoproject.com/en/2.0/ref/forms/fields/#disabled
from prettyjson import PrettyJSONWidget
class JsonForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(JsonForm, self).__init__(*args, **kwargs)
self.fields['json'].disabled = True
class Meta:
model = Test
fields = '__all__'
widgets = {
'myjsonfield': PrettyJSONWidget(),
}
class JsonAdmin(admin.ModelAdmin):
form = JsonForm
Using 0.2.2 on Django 1.9.4 It seems to not work with readonly_fields.
I think PrettyJSONWidget's render may run before render readonly_fields.