-
Notifications
You must be signed in to change notification settings - Fork 87
Description
Is your feature request related to a problem? Please describe.
When using the JSONField I would want to see the JSON content pretty printed.
Describe the solution you'd like
Currently starlette-admin uses the json.html template for rendering JSONField.
It uses the tojson filter, initial assumption was that it's the Jinja2's version, but it is not and starlette-admin seems to override it.
So I think the solution here is to just remove the override and rely on Jinja2's internal version. Not sure whether default=str is something we need to worry about though.
The solution for pretty printing would then be to create a separate template file in your application, like:
# templates/admin/json_pretty_print.html
<div id="{{ field.name }}" class="field-json">{{ data|tojson(indent=2) }}</div>
And then use it on a JSONField, like:
class MyModelView(ModelView):
fields = [
JSONField("json_data", display_template="admin/json_pretty_print.html")
]
Describe alternatives you've considered
- Could just add the indent option to the lambda function. However looking closely at the Jinja implementation, it does run htmlsafe over it, while the starlette-admin lambda doesn't.
- I found no way to override which filters get loaded into
starlette-admin
Additional context
n/a