def add_club(self, request, pk=None):
"""
Collaborate with another Club in this project.
"""
project = self.get_object()
club_id = int(request.query_params.get('club', -1))
if club_id == -1:
raise rest_exceptions.ValidationError(
'The request must contain a club!'
)
try:
club = models.Club.objects.get(id=club_id)
except models.Club.DoesNotExist:
raise rest_exceptions.ValidationError(
'The club does not exist!'
)
project.add_club(club)
serializer = serializers.ProjectSerializer(project)
return Response(serializer.data)
评论列表
文章目录