问题描述
在 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 的管理员中编辑对象(仅显示列表)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!