AirShelf/core/backend/apps/ops/serializers.py

48 lines
1.2 KiB
Python

from rest_framework import serializers
from .models import Notification
class NotificationSerializer(serializers.ModelSerializer):
type = serializers.CharField(source="notification_type", read_only=True)
unread = serializers.SerializerMethodField()
project_name = serializers.CharField(source="project.name", read_only=True)
class Meta:
model = Notification
fields = [
"id",
"type",
"notification_type",
"priority",
"title",
"brief",
"body",
"source",
"project",
"project_name",
"stage",
"owner_label",
"cost_label",
"related_url",
"is_read",
"unread",
"read_at",
"archived_at",
"metadata",
"created_at",
"updated_at",
]
read_only_fields = [
"id",
"type",
"project_name",
"read_at",
"archived_at",
"created_at",
"updated_at",
]
def get_unread(self, obj):
return not obj.is_read