-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The formatting does not work on read-only fields #21
Comments
Try making the field |
Nope, does not seem to work. |
What versions of Python, Django, and django-prettyjson are you using? What combination of disabled, editable, and readonly did you try? |
Python 3.3, Django 2.1, and latest for this library. Editable is set to False in my models. |
These lines of code in the django source could be helpful. It sets all fields to exclude, which will likely affect the callback later on, which is what uses the formfield_overrides |
I can confirm that including a But setting the field This can be done by overriding def get_form(self, *args, **kwargs):
form = super().get_form(*args, **kwargs)
my_json_field = form.base_fields["my_json_field"]
my_json_field.disabled = True
my_json_field.widget = PrettyJSONWidget(attrs={"initial": "parsed"})
return form Working with Django 2.2.5, django-prettyjson 0.4.1 |
I ran into this issue too. I tried your workaround @BenVosper and while this works for a user who has elevated permissions for a model, if the user only has the "view" permission for a model then Django automatically makes all fields read-only and as such django-prettyjson does nothing and the user just sees the plain text / string version of the JSON. @kevinmickey any thoughts on how to get django-prettyjson to work for read-only fields? |
Did any of you find a solution to easily format readonly JSONFields ? |
Add this to your admin instead of making the field read only
|
Since including a JSONField in readonly_fields prevents the PrettyJSONWidget from being used, instead of overriding formfield_overrides = {
JSONField: {
"widget": PrettyJSONWidget(
attrs={"initial": "parsed", "disabled": True}
)
}
} Working with Django 3.1.13, django-prettyjson 0.4.1 |
My code setup is as follows:
models.py
admin.py
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.
Is this by design? And is there any way to have the formatting work for read-only fields?
The text was updated successfully, but these errors were encountered: