How to disable add / view links in Django Admin


This is most simple steps that frequently used when we want to showing Log / Histories of Models in Django Admin.
Sometimes we don’t want to give detail/view links for record Models in Django Admin. We can disable them with :

1
2
3
4
5
6
7
8
class InsuranceHistoryAdmin(admin.ModelAdmin):
    """Paypal History Logger"""
    list_display = (‘id’, ’email’, ‘activation’, ‘account’,
                    ‘created’, ‘modified’, ‘payment_status’)

    def __init__(self, *args, **kwargs):
        super(InsuranceHistoryAdmin, self).__init__(*args, **kwargs)
        self.list_display_links = (None, )

Yes, you see that “self.list_display_links = (None, )” is our saviour.

Then, to disable add permission / delete permission, it simply as :

1
2
3
4
5
def has_add_permission(self, request):
    return False

def has_delete_permission(self, request, obj=None):
    return False

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.