Skip to content

Commit

Permalink
refactor: Add id and is_favorite
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis-Shtanskiy committed Jan 6, 2025
1 parent 5454848 commit 7b5b398
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/backend/api/v1/projects/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,11 +559,11 @@ class ReadListParticipationRequestSerializer(
project = ShortProjectSerializer(
exclude=["started", "ended", "direction", "project_status"]
)
is_favorite_profile = serializers.SerializerMethodField(read_only=True)
position = ShortProjectSpecialistSerializer()
request_status = serializers.SerializerMethodField()
request_participants = BaseProfileSerializer(
exclude=[
"user_id",
"specialists",
],
source="user.profile",
Expand All @@ -576,6 +576,7 @@ class Meta(BaseParticipationRequestSerializer.Meta):
"request_status",
"is_viewed",
"cover_letter",
"is_favorite_profile",
)
read_only_field = ("request_participants",)

Expand All @@ -586,6 +587,17 @@ def to_representation(self, instance):
)
return rep

def get_is_favorite_profile(self, profile) -> bool:
"""
Метод возвращает True если Владелец добавил участника в избранное.
В противном случе возвращает False.
"""
user = self.context.get("request", None).user
return (
user.is_authenticated
and profile.favorited_by.filter(id=user.pk).exists()
)

def get_request_status(self, obj) -> str:
"""Метод получения статуса запроса."""

Expand Down

0 comments on commit 7b5b398

Please sign in to comment.