Disable link to edit object in django's admin (display list only)?

后端 未结 12 480
渐次进展
渐次进展 2020-12-12 22:05

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

12条回答
  •  有刺的猬
    2020-12-12 22:30

    I wanted a Log viewer as a list only.

    I got it working like this:

    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.

    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.

提交回复
热议问题