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 的管理员中编辑对象(仅显示列表)?
基础教程推荐
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
