-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathadmin.py
More file actions
29 lines (21 loc) · 1000 Bytes
/
admin.py
File metadata and controls
29 lines (21 loc) · 1000 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from django.contrib import admin
from generic_notifications.models import (
Notification,
NotificationFrequencyPreference,
NotificationTypeChannelPreference,
)
@admin.register(Notification)
class NotificationAdmin(admin.ModelAdmin):
list_display = ["recipient", "notification_type", "added", "get_channels"]
def get_queryset(self, request):
return super().get_queryset(request).prefetch_related("channels")
@admin.display(description="Channels")
def get_channels(self, obj):
channels = obj.channels.values_list("channel", flat=True)
return ", ".join(channels) if channels else "-"
@admin.register(NotificationTypeChannelPreference)
class NotificationTypeChannelPreferenceAdmin(admin.ModelAdmin):
list_display = ["user", "notification_type", "channel", "enabled"]
@admin.register(NotificationFrequencyPreference)
class NotificationFrequencyPreferenceAdmin(admin.ModelAdmin):
list_display = ["user", "notification_type", "frequency"]