diff --git a/profiles/viewsets.py b/profiles/viewsets.py index 937b3cc..b324dda 100644 --- a/profiles/viewsets.py +++ b/profiles/viewsets.py @@ -17,6 +17,8 @@ class ProfileViewSet(viewsets.ModelViewSet): permission_classes = (permissions.IsAuthenticatedOrReadOnly,) def retrieve(self, request: HttpRequest, pk=None): + if (not ProfileModel.objects.filter(pk=pk).exists()): + return Response({"detail": "Profile not found."}, status=status.HTTP_404_NOT_FOUND) instance = ProfileModel.objects.get(pk=pk) instance.avatar_url.name = instance.avatar_url.name[instance.avatar_url.name.find("static") - 1:] return Response(self.serializer_class(instance).data, @@ -32,9 +34,8 @@ class ProfileViewSet(viewsets.ModelViewSet): serializer.save(user=self.request.user) def perform_update(self, serializer): - query: QuerySet = ProfileModel.objects.filter(pk=self.request.user.pk) - if (not query.exists()): - return Response("profile not found", status=status.HTTP_400_BAD_REQUEST) + if (not ProfileModel.objects.filter(pk=pk).exists()): + return Response({"detail": "Profile not found."}, status=status.HTTP_404_NOT_FOUND) profile: ProfileModel = ProfileModel.objects.get(pk=self.request.user.pk) avatar = self.request.data.get("file", None) if (avatar is not None):