Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add user friendly json editor to django admin

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

like image 979
anyavacy Avatar asked Aug 01 '18 12:08

anyavacy


2 Answers

You can use prettyjson's PrettyJSONWidget:

class ProductModelForm(forms.ModelForm):
    class Meta:
        fields = (
            ...
            'my_column',
        )
        widgets = {
            'my_column': PrettyJSONWidget(),
        }
like image 138
Botte Oleksandr Avatar answered Sep 24 '22 20:09

Botte Oleksandr


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

like image 32
anyavacy Avatar answered Sep 24 '22 20:09

anyavacy