def get(self, request, format=None): user = User.objects.get(pk=request.user.pk) client = Client.objects.get(user=user) team = Team.objects.get(client_id=client.id) team_member_ids = TeamMember.objects.filter(team_id=team.id)\ .values_list('id', flat=True)\ .order_by('id')\ .distinct() res = [] for team_member_id in team_member_ids: team_member = TeamMember.objects.get(id=team_member_id) team_member_serializer = TeamMemberSerializer(team_member) shared_profiles_by_team_member = SharedProfile.objects.filter(team_member_id=team_member_id) talent_ids = shared_profiles_by_team_member.order_by('talent')\ .values_list('talent').distinct() talents = Talent.objects.filter(id__in=talent_ids) if len(talents) > 0: talents_serializer = TalentSimpleSerializer(talents, many=True) res.append({ 'team_member': team_member_serializer.data, 'talents': talents_serializer.data }) serializer = SharedTalentByTeamMemberSerializer(data=res, many=True) return JsonResponse(res, safe=False)
def get(self, request, format=None): user = User.objects.get(pk=request.user.pk) client = Client.objects.get(user=user) team = Team.objects.get(client_id=client.id) # Find a team which include you as a team member team_member_ids = TeamMember.objects.filter(Q(member_email=client.user.email) & ~Q(team_id=team.id))\ .values_list('id', flat=True).order_by('id').distinct() shared_profiles = SharedProfile.objects.filter(team_member_id__in=team_member_ids) shared_talent_ids = shared_profiles.order_by('talent_id').values_list('talent_id', flat=True).distinct() res = [] for shared_talent_id in shared_talent_ids: talent = Talent.objects.get(id=shared_talent_id) talent_serializer = TalentSimpleSerializer(talent) shared_team_member_ids = SharedProfile.objects.filter( team_member_id__in=team_member_ids, talent_id=shared_talent_id ) team_members = TeamMember.objects.filter(id__in=shared_team_member_ids) if len(team_members) > 0: team_members_serializer = TeamMemberSerializer(team_members, many=True) res.append({ 'talent': talent_serializer.data, 'team_members': team_members_serializer.data }) serializer = SharedTalentSerializer(data=res, many=True) return JsonResponse(res, safe=False)
class ClientRequestDetailSerializer(serializers.ModelSerializer): client = ClientSerializer(many=False, read_only=True) talent = TalentSimpleSerializer(many=False, read_only=True) class Meta: model = ClientRequest fields = ('id', 'client', 'talent', 'request', 'created')
class TalentRatingDetailSerializer(serializers.ModelSerializer): talent = TalentSimpleSerializer(many=False) class Meta: model = TalentRating fields = ('id', 'talent', 'rating', 'comments', 'client', 'updated', 'casting_request_talent')
class SharedProfileDetailSerializer(serializers.ModelSerializer): team_member = TeamMemberDetailSerializer(many=False, read_only=True) talent = TalentSimpleSerializer(many=False, read_only=True) class Meta: model = SharedProfile fields = ('id', 'team_member', 'talent', 'comment', 'created') def create(self, validated_data): return SharedProfile.objects.create(**validated_data)
class CallBackDetailSerializer(serializers.ModelSerializer): talent = TalentSimpleSerializer(many=False, read_only=True) class Meta: model = CallBack fields = ('id', 'client', 'talent', 'created')
class SharedTalentSerializer(serializers.Serializer): talent = TalentSimpleSerializer(many=False) team_members = TeamMemberSerializer(many=True)
class FavoriteDetailSerializer(serializers.ModelSerializer): talent = TalentSimpleSerializer(many=False, read_only=True) class Meta: model = Favorite fields = ('id', 'client', 'talent', 'viewed_time')
class BlockedProfileDetailSerializer(serializers.ModelSerializer): talent = TalentSimpleSerializer(many=False, read_only=True) class Meta: model = BlockedProfile fields = ('id', 'client', 'talent', 'blocked_time', 'description')