From 54afa8aae54f465457ec19b504f20930d21a1d2d Mon Sep 17 00:00:00 2001 From: starnakin Date: Wed, 6 Dec 2023 16:48:21 +0100 Subject: [PATCH] move image path --- profiles/viewsets.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/profiles/viewsets.py b/profiles/viewsets.py index 25bbd6f..b07582a 100644 --- a/profiles/viewsets.py +++ b/profiles/viewsets.py @@ -4,7 +4,7 @@ from rest_framework import permissions, status from rest_framework import viewsets from rest_framework.response import Response - +from django.http import HttpRequest from django.db.models import QuerySet from .serializers import ProfileSerializer @@ -16,6 +16,12 @@ class ProfileViewSet(viewsets.ModelViewSet): parser_classes = (MultiPartParser, FormParser) permission_classes = (permissions.IsAuthenticatedOrReadOnly,) + def retrieve(self, request: HttpRequest, pk=None): + instance = self.get_object() + instance.avatar_url.name = instance.avatar_url.name.replace("profiles", "", 1) + return Response(self.serializer_class(instance).data, + status=status.HTTP_200_OK) + def perform_create(self, serializer): serializer.save(user=self.request.user)