sqladmin
sqladmin copied to clipboard
Details page not respecting the format I am passing
Checklist
- [X] The bug is reproducible against the latest release or
master. - [X] There are no similar issues or pull requests to fix it yet.
Describe the bug
Hi,
I am passing a custom formatter for the Details page like this:
# field1 is a dictionary
column_formatters_detail = {"column1": lambda m, a: json.dumps(m.field1, indent=4)}
However, when I go to the details page that formatting (pretty json) is not there, it still appears as a single json line. Is this a bug? How can I correct this without having to alter the templates? (no html). Is it possible to do it with WTForms?
Steps to reproduce the bug
No response
Expected behavior
No response
Actual behavior
No response
Debugging material
No response
Environment
OS: Ubuntu 22.04 Python3.11 sqladmin version = 0.20.1
Additional context
No response
The culprit seems to be a tabler css rule: .text-nowrap { white-space: nowrap !important; }. You can override that rule.
This is my workaround which is good enough for me, without having to touch CSS:
from markupsafe import Markup
# ...
column_formatters_detail = {
MyModel.my_column: lambda m, _: Markup(
f"""
<pre>{json.dumps(m.my_column, indent=4)}</pre>
"""
),
}
Basically wrap your json string in <pre> tag.