Django Admin:改变数据的显示方式
我有一个带有 json 字段的模型。其内容可能打印得漂亮,也可能不漂亮,只要数据有效,我并不介意。然而,当它显示在 django admin 中时,我希望该字段的内容打印得漂亮,以便于阅读。我不介意这是否意味着漂亮的打印版本会被保存。
有关如何执行此操作的任何提示?
I have a model with a json field. The contents of which may or may not be pretty-printed, I don't really mind either way as long as the data is valid. However when it is displayed in django admin I would like for the contents of the field to be pretty printed so that it is easy to read. I don't mind if this means the pretty printed version is then saved.
Any tips on how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
回答我自己的问题...
阅读了 Matthew J Morrison 向我指出的附近的文档后。我发现我可以添加 JavaScript 来改变一些事情。
在我的 ModelAdmin 中,我添加了
来自 Douglas Crockford 的网站
json2.js
当你知识。
Answering my own question...
After reading the documentation near what Matthew J Morrison pointed me to. I discovered I could add a javascript to alter things.
to my ModelAdmin I added
json2.js is from Douglas Crockford's website
custom.js is
Easy when you know how.
也许创建一个自定义小部件...
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_overrides
Maybe create a custom widget...
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_overrides