I have a django app, using also rest_framework
, and a model Product
with field of type JSONField
. so data is stored as JSON
in Postgres
, Now I want to provide the admin with a nice user friendly way on how he can change the json field (names/keys and values)
. is there an extension for that or is there a faster way on how to do that.
here is the column definition in the database.
my_column = JSONField(default={"editorial1": "text 1", "editorial_2": "text2", "editorial_3": "text"})
BOTH KEYS AND VALUES SHOULD BE EDITABLE BY THE ADMIN
The admin should not know anything about JSON, and should not enter/edit any json format field
You can use prettyjson
's PrettyJSONWidget
:
class ProductModelForm(forms.ModelForm):
class Meta:
fields = (
...
'my_column',
)
widgets = {
'my_column': PrettyJSONWidget(),
}
I ended up using the django-admin-json-editor
. Not the best thing in the world, but it does the trick
https://github.com/abogushov/django-admin-json-editor
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With