extensions-website/notifications/admin.py
Pablo Vazquez c38fb20519 Admin: Improve notifications list
Instead of showing a list of "Notification object (xxx)", show columns
for actor, verb, target, recipient, and a link to view it in context.
2024-07-27 19:25:54 +02:00

39 lines
986 B
Python

from django.contrib import admin
from django.utils.html import format_html
from notifications.models import Notification
class NotificationAdmin(admin.ModelAdmin):
readonly_fields = (
'recipient',
'action',
'email_sent',
'processed_by_mailer_at',
'read_at',
)
fields = readonly_fields
list_display = ('actor', 'verb', 'target', 'recipient', 'view_link')
list_display_links = ['verb']
def get_queryset(self, request):
return Notification.objects.all()
def verb(self, obj):
return obj.action.verb
def actor(self, obj):
return obj.action.actor
def target(self, obj):
return obj.action.target
@staticmethod
def view_link(obj) -> str:
"""Link to view the notification content in context."""
template = '<a href="{:s}">View</a>'.format(obj.get_absolute_url())
return format_html(template)
admin.site.register(Notification, NotificationAdmin)