<s> from rest_framework import viewsets <EOL> from rest_framework import permissions <EOL> from rest_framework import filters , status <EOL> from rest_framework . response import Response <EOL> from profiles . models import Notification <EOL> from . serializers import NotificationSerializer <EOL> class NotificationViewset ( viewsets . ModelViewSet ) : <EOL> permission_classes = ( permissions . IsAuthenticated , ) <EOL> paginate_by = <NUM_LIT:20> <EOL> serializer_class = NotificationSerializer <EOL> filter_backends = ( filters . DjangoFilterBackend , filters . OrderingFilter , ) <EOL> filter_fields = ( '<STR_LIT>' , ) <EOL> ordering_fields = ( '<STR_LIT>' , ) <EOL> def get_queryset ( self ) : <EOL> user = self . request . user <EOL> return user . notifications . select_related ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def mark_as_read_all_notification ( self , request ) : <EOL> user = self . request . user <EOL> user . notifications . filter ( is_read = False ) . update ( is_read = True ) <EOL> return Response ( status = status . HTTP_200_OK ) <EOL> def mark_as_read_single_notification ( self , request , pk = None ) : <EOL> notification = self . get_object ( ) <EOL> notification . is_read = True <EOL> notification . save ( ) <EOL> return Response ( status = status . HTTP_200_OK ) <EOL> notification_list = NotificationViewset . as_view ( <EOL> { '<STR_LIT>' : '<STR_LIT:list>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> ) <EOL> notification_detail = NotificationViewset . as_view ( <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> ) </s>
