JSON Widget Design
Goal: Beautify all JSONField displays in Django admin using django-json-widget for editable fields and a prettify_json helper for readonly fields.
Approach
Use django-json-widget to replace the default textarea with a collapsible, syntax-highlighted JSON editor. For readonly JSON fields, use a format_html helper that renders pretty-printed JSON in a styled <pre> block.
Scope
Editable JSON fields (get widget)
| App | Model | Field |
|---|---|---|
orchestration | PipelineDefinition | config, tags |
orchestration | StageExecution | output_snapshot |
notify | NotificationChannel | config |
Readonly JSON fields (get prettify_json display)
| App | Model | Field |
|---|---|---|
alerts | Alert | labels, annotations, raw_payload |
alerts | Incident | metadata |
alerts | AlertHistory | details |
checkers | CheckRun | metrics |
intelligence | AnalysisRun | provider_config, recommendations |
Implementation
- Add
django-json-widgettopyproject.tomland install - Add
"django_json_widget"toINSTALLED_APPSinconfig/settings.py - Create a shared
prettify_jsonhelper in a common location - Apply
JSONEditorWidgetviaformfield_overrideson admins with editable JSON fields - Add
prettify_jsonreadonly display methods on admins with readonly JSON fields