Skip to content

Commit

Permalink
Merge pull request #400 from Pet-projects-CodePET/refactor/requests_a…
Browse files Browse the repository at this point in the history
…nd_serializers

refactor: Add id and is_favorite
  • Loading branch information
Denis-Shtanskiy authored Jan 6, 2025
2 parents 4eea0ed + 7b5b398 commit 0077c59
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 @@ -560,11 +560,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 @@ -577,6 +577,7 @@ class Meta(BaseParticipationRequestSerializer.Meta):
"request_status",
"is_viewed",
"cover_letter",
"is_favorite_profile",
)
read_only_field = ("request_participants",)

Expand All @@ -587,6 +588,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 0077c59

Please sign in to comment.