add: profiles and profile page
This commit is contained in:
@ -11,22 +11,22 @@ from .serializers import ProfileSerializer
|
||||
from .models import ProfileModel
|
||||
|
||||
class ProfileViewSet(viewsets.ModelViewSet):
|
||||
queryset = ProfileModel.objects.order_by('-pk')
|
||||
queryset = ProfileModel.objects.all()
|
||||
serializer_class = ProfileSerializer
|
||||
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)
|
||||
instance.avatar_url.name = instance.avatar_url.name[instance.avatar_url.name.find("static") - 1:]
|
||||
return Response(self.serializer_class(instance).data,
|
||||
status=status.HTTP_200_OK)
|
||||
|
||||
def get_queryset(self):
|
||||
profiles = ProfileModel.objects.all()
|
||||
for profile in profiles:
|
||||
profile.avatar_url.name = profile.avatar_url.name.replace("profiles", "", 1)
|
||||
return profiles
|
||||
def list(self, request: HttpRequest):
|
||||
serializer = ProfileSerializer(self.queryset, many=True)
|
||||
for profile in serializer.data:
|
||||
profile["avatar_url"] = profile["avatar_url"][profile["avatar_url"].find("static") - 1:]
|
||||
return Response(serializer.data)
|
||||
|
||||
def perform_create(self, serializer):
|
||||
serializer.save(user=self.request.user)
|
||||
|
Reference in New Issue
Block a user