I'm doing a study assignment. when checking, the teacher made a remark, what did he mean?

` I'm doing a study assignment. when checking, the teacher made a remark, what did he mean? I left a comment in the code

''' Views for 'users' API application. '''

class SubscriptionsViewSet(viewsets.GenericViewSet):
    ''' ViewSet for user subscription actions. '''
    serializer_class = UserSubscriptionSerializer

    def get_queryset(self):
        return self.request.user.subscriptions.all()

    @action(detail=True, methods=['post', 'delete'], name='subscribe')
    def subscribe(self, request, pk=None):
        ''' Process user subscription actions.. '''
        subscribed = get_object_or_404(get_user_model(), id=pk)
        if self.request.method == 'DELETE':
            request.user.subscriptions.remove(subscribed)
            return Response(status=status.HTTP_204_NO_CONTENT)
        if request.user.subscriptions.filter(id=subscribed.id).exist():
#! Here, most likely, you need to return Response
            raise validators.ValidationError(
                _('The subscription already exists.')
            )
        request.user.subscriptions.add(subscribed)
        serializer = self.get_serializer(instance=subscribed)
        return Response(serializer.data, status=status.HTTP_201_CREATED)

`

Back to Top