18 lines
730 B
Python
18 lines
730 B
Python
# apps/notification/serializers.py
|
|
from rest_framework import serializers
|
|
from apps.notification.models import Notification
|
|
from apps.accounts.models import User
|
|
|
|
class NotificationSerializer(serializers.ModelSerializer):
|
|
sender = serializers.PrimaryKeyRelatedField(queryset=User.objects.all())
|
|
receiver = serializers.PrimaryKeyRelatedField(read_only=True)
|
|
created_at = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S', read_only=True)
|
|
|
|
class Meta:
|
|
model = Notification
|
|
fields = [
|
|
'id', 'sender', 'receiver', 'title', 'content', 'type',
|
|
'related_resource', 'is_read', 'created_at'
|
|
]
|
|
read_only_fields = ['id', 'receiver', 'created_at', 'is_read']
|
|
|