django管理员/内联中的只读字段 [英] Readonly fields in the django admin/inline
问题描述
我使用此代码段,将管理后台中的多个字段显示为只读方式,但以在评论中注意到,它不能在堆栈线/表格线上工作。有没有办法实现这一点?我有一个附加到模型的对象的列表,只是想在模型的细节视图中显示它,而没有可能改变值。
I use this snippet to show several fields in my admin backend as readonly, but as noticed in the comments, it does not work on stackedinline/tabularinline. Is there any other way to achieve this? I have a list of objects attached to a model and just want to show it in the model's details view without the possibility to change values.
推荐答案
如果您正在运行Django 1.3或更高版本;有一个名为 ModelAdmin.readonly_fields 可以使用。
If you are running Django 1.3 or later; there's an attribute named ModelAdmin.readonly_fields which you could use.
InlineModelAdmin
继承自 ModelAdmin
,所以你应该可以使用它从你的内联子类。
InlineModelAdmin
inherits from ModelAdmin
, so you should be able to use it from your inline subclass.
这篇关于django管理员/内联中的只读字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!