fix: profile: block: fix test and simplify code

This commit is contained in:
2024-04-08 13:00:46 +02:00
parent 9bbe5a4705
commit c1624cce83
2 changed files with 9 additions and 4 deletions

View File

@ -2,6 +2,7 @@ from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import permissions, status
from rest_framework.authentication import SessionAuthentication
from rest_framework.request import Request
from django.contrib.auth.models import User
from django.utils.translation import gettext as _
@ -15,11 +16,11 @@ class GetBlocksView(APIView):
permission_classes = (permissions.IsAuthenticated,)
authentication_classes = (SessionAuthentication,)
def get(self, request):
def get(self, request: Request):
profiles = []
blocks = BlockModel.objects.filter(blocker=request.user.pk)
blocks = BlockModel.objects.filter(blocker=request.user)
for block in blocks:
profile = ProfileModel.objects.filter(user_id=block.blocked.pk)
profile = ProfileModel.objects.filter(user=block.blocked)
if (profile.exists()):
profiles.append(profile[0])