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

后端 未结 12 540
渐次进展
渐次进展 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:51

    As user, omat, mentioned in a comment above, any attempt to simply remove the links does not prevent users from still accessing the change page manually. However, that, too, is easy enough to remedy:

    class MyModelAdmin(admin.ModelAdmin)
        # Other stuff here
        def change_view(self, request, obj=None):
            from django.core.urlresolvers import reverse
            from django.http import HttpResponseRedirect
            return HttpResponseRedirect(reverse('admin:myapp_mymodel_changelist'))
    

提交回复
热议问题