profiles(block): get profiles of blocked users

This commit is contained in:
AdrienLSH
2024-04-07 17:43:30 +02:00
parent 8912e39fa4
commit 80e7335c8d
4 changed files with 40 additions and 47 deletions

View File

@ -1,10 +1,21 @@
from rest_framework.serializers import ModelSerializer
from rest_framework.serializers import (ModelSerializer,
ReadOnlyField,
SerializerMethodField)
from ..models import ProfileModel
from ..models import BlockModel
class BlockSerializer(ModelSerializer):
blocked_username = ReadOnlyField(source='blocked.username')
blocked_avatar = SerializerMethodField()
class Meta:
model = BlockModel
fields = ['blocked']
fields = ['blocked', 'blocked_username', 'blocked_avatar']
def get_blocked_avatar(self, instance):
blocked_profile = ProfileModel.objects.filter(user_id=instance.blocked.pk)
if (blocked_profile.exists()):
return blocked_profile[0].avatar.name
return '/static/avatars/default.avif'