禁用在django的管理员中编辑对象的链接(仅限显示列表)? [英] Disable link to edit object in django's admin (display list only)?

查看:156
本文介绍了禁用在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, )



It is kind of a mix between both answers.

如果你只是做 self.list_display_links =()它将显示链接,无论如何,因为模板标签代码(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的管理员中编辑对象的链接(仅限显示列表)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆