47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
from rest_framework import serializers
|
|
from manage_notifications.models import (
|
|
IAmPrincipalNotificationSettings,
|
|
InAppNotification,
|
|
NotificationCategoryChoices,
|
|
)
|
|
|
|
|
|
class IAmPrincipalNotificationSettingsSerializer(serializers.ModelSerializer):
|
|
notification_category_display = serializers.SerializerMethodField()
|
|
|
|
def get_notification_category_display(self, obj):
|
|
return obj.get_notification_category_display()
|
|
|
|
class Meta:
|
|
model = IAmPrincipalNotificationSettings
|
|
fields = [
|
|
"id",
|
|
"notification_category",
|
|
"notification_category_display",
|
|
"is_enabled",
|
|
]
|
|
|
|
|
|
class InAppNotificationSerializer(serializers.ModelSerializer):
|
|
notification_category = serializers.ChoiceField(
|
|
choices=NotificationCategoryChoices.choices
|
|
)
|
|
|
|
class Meta:
|
|
model = InAppNotification
|
|
fields = [
|
|
"id",
|
|
"title",
|
|
"message",
|
|
"notification_category",
|
|
"created_on",
|
|
"principal",
|
|
]
|
|
|
|
# def to_representation(self, instance):
|
|
# representation = super().to_representation(instance)
|
|
# representation["notification_category"] = (
|
|
# NotificationCategoryChoices.name_for_value(instance.notification_category)
|
|
# )
|
|
# return representation
|