Friday, October 22, 2021

Adding LogEntry to Django Admin

from django.contrib.admin.models import LogEntry, DELETION

from django.utils.html import escape

from django.urls import reverse

from django.utils.safestring import mark_safe


class LogEntryAdmin(admin.ModelAdmin):

    date_hierarchy = 'action_time'

    list_filter = [





    search_fields = [




    list_display = [







    def has_add_permission(self, request):

        return False

    def has_change_permission(self, request, obj=None):

        return False

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

        return False

    def has_view_permission(self, request, obj=None):

        return request.user.is_superuser

    def object_link(self, obj):

        if obj.action_flag == DELETION:

            link = escape(obj.object_repr)


            ct = obj.content_type

            link = '<a href="%s">%s</a>' % (

                reverse('admin:%s_%s_change' % (ct.app_label, ct.model), args=[obj.object_id]),



        return mark_safe(link)

    object_link.admin_order_field = "object_repr"

    object_link.short_description = "object"

1 comment:

  1. How to Play Betway Casino? - Learn How to Play
    Casino. What is 벳 365 the Best Betway Casino? 라이브스코어 · Learn How to 실시간 배당 Use it: · Payouts: · Casino Games: · 텍사스홀덤 Deposit Methods: · Software and Markets: · Casino Bonuses:. 램 슬롯