This repository has been archived on 2022-09-23. You can view files and clone it, but cannot push or open issues or pull requests.
microservices/api/admin.py

56 lines
1.6 KiB
Python
Raw Normal View History

2022-05-08 07:32:22 +02:00
from django.contrib import admin
2022-05-08 08:22:01 +02:00
from django.contrib.admin.models import LogEntry, DELETION
from django.utils.html import escape
from django.utils.safestring import mark_safe
from django.urls import reverse
from .models import api
2022-05-08 07:32:22 +02:00
2022-05-08 08:22:01 +02:00
@admin.register(LogEntry)
class LogEntryAdmin(admin.ModelAdmin):
# to have a date-based drilldown navigation in the admin page
date_hierarchy = 'action_time'
# to filter the resultes by users, content types and action flags
list_filter = ['user', 'content_type', 'action_flag']
# when searching the user will be able to search in both object_repr and change_message
search_fields = ["object_repr", "change_message"]
list_display = [
"action_time",
"user",
"content_type",
"action_flag",
"object_link",
]
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_staff
def object_link(self, obj):
if obj.action_flag == DELETION:
link = escape(obj.object_repr)
else:
ct = obj.content_type
link = '<a href="%s">%s</a>' % (
reverse(
"admin:%s_%s_change" % (ct.app_label, ct.model),
args=[obj.object_id],
),
escape(obj.object_repr),
)
return mark_safe(link)
object_link.admin_order_field = "object_repr"
object_link.short_description = "object"