Compare commits

..

No commits in common. "fb1b71ade6f2477049658be563a0e789ebd6eace" and "336257d1d0582a0b5d8a42969c185960bd7f5d52" have entirely different histories.

View File

@ -11,19 +11,19 @@ from .serializers import ProfileSerializer
from .models import ProfileModel from .models import ProfileModel
class ProfileViewSet(viewsets.ModelViewSet): class ProfileViewSet(viewsets.ModelViewSet):
queryset = ProfileModel.objects.all queryset = ProfileModel.objects.all()
serializer_class = ProfileSerializer serializer_class = ProfileSerializer
parser_classes = (MultiPartParser, FormParser) parser_classes = (MultiPartParser, FormParser)
permission_classes = (permissions.IsAuthenticatedOrReadOnly,) permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
def retrieve(self, request: HttpRequest, pk=None): def retrieve(self, request: HttpRequest, pk=None):
instance = ProfileModel.objects.get(pk=pk) instance = self.get_object()
instance.avatar_url.name = instance.avatar_url.name[instance.avatar_url.name.find("static") - 1:] instance.avatar_url.name = instance.avatar_url.name[instance.avatar_url.name.find("static") - 1:]
return Response(self.serializer_class(instance).data, return Response(self.serializer_class(instance).data,
status=status.HTTP_200_OK) status=status.HTTP_200_OK)
def list(self, request: HttpRequest): def list(self, request: HttpRequest):
serializer = ProfileSerializer(self.queryset(), many=True) serializer = ProfileSerializer(self.queryset, many=True)
for profile in serializer.data: for profile in serializer.data:
profile["avatar_url"] = profile["avatar_url"][profile["avatar_url"].find("static") - 1:] profile["avatar_url"] = profile["avatar_url"][profile["avatar_url"].find("static") - 1:]
return Response(serializer.data) return Response(serializer.data)