pythondjangodjango-adminmodeladmin

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


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).

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?


Solution

  • 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.