from rest_framework import serializers


class GetNotifSerializer(serializers.ModelSerializer):
    send_by = UserSerializer()
    is_seen = serializers.SerializerMethodField()
    read_by = UserSerializer(many=True)
    class Meta:
        model = NotifModel
        fields = ('id', 'subject', 'priority', 'description', 'send_time', 'is_seen', 'send_by', 'read_by')
        read_only_fields = ("read_by", "send_by")
    def get_is_seen(self, obj):
        user = self.context['user']
        return user in obj.read_by.all()