28 lines
961 B
Python
28 lines
961 B
Python
from rest_framework import serializers
|
|
from apps.core.serializers import AsyncModelSerializer
|
|
from .models import Notification, AlertRule
|
|
|
|
|
|
class NotificationSerializer(AsyncModelSerializer):
|
|
category_name = serializers.CharField(source="get_category_display", read_only=True)
|
|
|
|
class Meta:
|
|
model = Notification
|
|
fields = [
|
|
"id", "title", "content", "category", "category_name",
|
|
"link", "is_read", "read_at", "extra_data", "created_at",
|
|
]
|
|
read_only_fields = ["id", "created_at"]
|
|
|
|
|
|
class AlertRuleSerializer(AsyncModelSerializer):
|
|
rule_type_name = serializers.CharField(source="get_rule_type_display", read_only=True)
|
|
|
|
class Meta:
|
|
model = AlertRule
|
|
fields = [
|
|
"id", "code", "name", "rule_type", "rule_type_name",
|
|
"threshold", "is_enabled", "channels", "created_at", "updated_at",
|
|
]
|
|
read_only_fields = ["id", "created_at", "updated_at"]
|