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 的管理员中编辑对象(仅显示列表)?


- 如何在 Python 的元组列表中对每个元组中的第一个值求和? 2022-01-01
- python check_output 失败,退出状态为 1,但 Popen 适用于相同的命令 2022-01-01
- padding='same' 转换为 PyTorch padding=# 2022-01-01
- 沿轴计算直方图 2022-01-01
- 如何将一个类的函数分成多个文件? 2022-01-01
- 分析异常:路径不存在:dbfs:/databricks/python/lib/python3.7/site-packages/sampleFolder/data; 2022-01-01
- 使用Heroku上托管的Selenium登录Instagram时,找不到元素';用户名'; 2022-01-01
- python-m http.server 443--使用SSL? 2022-01-01
- pytorch 中的自适应池是如何工作的? 2022-07-12
- 如何在 python3 中将 OrderedDict 转换为常规字典 2022-01-01