Pseudo-form in Django admin that generates a json object on save

前端 未结 7 1087
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-23 18:07

I have a model with a field for a json object. This object is used on the site to control some css variables, among other things.

Right now in the admin, I have a t

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-23 18:49

    Basically it sounds like you want a custom widget for your text field. The snippet on this page gives an example on how to render json key-value pairs. Even if it doesn't suit your needs entirely, especially as your nested json adds some complexity, it perhaps can give you some ideas.

    As for the pure storage and retrieval of json objects into Python dicts, a few reusable JSONField implementations exist, like this one. You might want to add it to the mix.

提交回复
热议问题