34 lines
1.0 KiB
Python
34 lines
1.0 KiB
Python
from django.shortcuts import get_object_or_404
|
|
from django.db import transaction
|
|
|
|
from rest_framework.viewsets import ReadOnlyModelViewSet
|
|
from rest_framework.views import APIView
|
|
from rest_framework.response import Response
|
|
from rest_framework import status
|
|
|
|
from .serializers import *
|
|
from .models import *
|
|
from .services import *
|
|
|
|
from users.services import *
|
|
|
|
|
|
# Create your views here.
|
|
class NotificationReadViewSet(ReadOnlyModelViewSet):
|
|
serializer_class = NotificationSerializer
|
|
|
|
# 30일 이전 알림만 가져옴
|
|
def get_queryset(self):
|
|
qs = UserToNotificationService.get_all_notification(self.request.user)
|
|
print(qs)
|
|
return qs.select_related(
|
|
'project_invitation__project',
|
|
'project_invitation__from_user',
|
|
)
|
|
|
|
def retrieve(self, request, *args, **kwargs):
|
|
instance = self.get_object()
|
|
instance.is_read = True
|
|
instance.save()
|
|
serializer = self.get_serializer(instance)
|
|
return Response(serializer.data, status=status.HTTP_200_OK) |