Skip to content

Commit b6e38b2

Browse files
authored
Closes #14690: Pretty-format JSON fields in the config form (#15623)
* Closes #14690: Pretty-format JSON fields in the config form * Revert changes * Use our own JSONField for config parameters for pretty editor outputs * Compare identity instead of equality
1 parent 90d0104 commit b6e38b2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

netbox/core/forms/model_forms.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from django import forms
55
from django.conf import settings
6+
from django.forms.fields import JSONField as _JSONField
67
from django.utils.translation import gettext_lazy as _
78

89
from core.forms.mixins import SyncedDataMixin
@@ -12,7 +13,7 @@
1213
from netbox.registry import registry
1314
from netbox.utils import get_data_backend_choices
1415
from utilities.forms import BootstrapMixin, get_field_value
15-
from utilities.forms.fields import CommentField
16+
from utilities.forms.fields import CommentField, JSONField
1617
from utilities.forms.widgets import HTMXSelect
1718

1819
__all__ = (
@@ -132,6 +133,9 @@ def __new__(mcs, name, bases, attrs):
132133
'help_text': param.description,
133134
}
134135
field_kwargs.update(**param.field_kwargs)
136+
if param.field is _JSONField:
137+
# Replace with our own JSONField to get pretty JSON in config editor
138+
param.field = JSONField
135139
param_fields[param.name] = param.field(**field_kwargs)
136140
attrs.update(param_fields)
137141

0 commit comments

Comments
 (0)