Disable link to edit object in django#39;s admin (display list only)?(禁用链接以在 django 的管理员中编辑对象(仅显示列表)?)
问题描述
在 Django 的管理员中,我希望禁用选择要更改的项目"页面上提供的链接,以便用户无法去任何地方编辑该项目.(我将把用户可以用这个列表做的事情限制在一组下拉操作中——没有实际的字段编辑).
In Django's admin, I want disable the links provided on the "select item to change" page so that users cannot go anywhere to edit the item. (I am going to limit what the users can do with this list to a set of drop down actions - no actual editing of fields).
我看到 Django 有能力 选择哪些字段显示链接,但是,我看不出我如何none.
I see that Django has the ability to choose which fields display the link, however, I can't see how I can have none of them.
class HitAdmin(admin.ModelAdmin):
list_display = ('user','ip','user_agent','hitcount')
search_fields = ('ip','user_agent')
date_hierarchy = 'created'
list_display_links = [] # doesn't work, goes to default
任何想法如何在没有任何编辑链接的情况下获取我的对象列表?
Any ideas how to get my object list without any links to edit?
推荐答案
我只想要一个日志查看器作为一个列表.
I wanted a Log viewer as a list only.
我是这样工作的:
class LogEntryAdmin(ModelAdmin):
actions = None
list_display = (
'action_time', 'user',
'content_type', 'object_repr',
'change_message')
search_fields = ['=user__username', ]
fieldsets = [
(None, {'fields':()}),
]
def __init__(self, *args, **kwargs):
super(LogEntryAdmin, self).__init__(*args, **kwargs)
self.list_display_links = (None, )
这是两种答案的混合.
如果你只是做 self.list_display_links = () 它将显示链接,无论如何,因为 template-tag 代码 (templatetags/admin_list.py) 再次检查查看列表是否为空.
If you just do self.list_display_links = () it will show the link, Anyway because the template-tag code (templatetags/admin_list.py) checks again to see if the list is empty.
这篇关于禁用链接以在 django 的管理员中编辑对象(仅显示列表)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:禁用链接以在 django 的管理员中编辑对象(仅显示列表)?
基础教程推荐
- 修改列表中的数据帧不起作用 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 包装空间模型 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 求两个直方图的卷积 2022-01-01
