def delete_resource(self, request, pk): user = self.get_object() book = get_object_or_404(Resource, id=self.request.data['resource']) user.resources.remove(book) return Response( ResourceSlimSerializer(self.get_object().resources, many=True).data)
def add_resource(self, request, pk): user = self.get_object() if 'resource' in self.request.data: book = get_object_or_404(Resource, id=self.request.data['resource']) user.resources.add(book) if 'sequence' in self.request.data: seq = get_object_or_404(Sequence, id=request.data['sequence']) for i in seq.resources.all(): user.resources.add(i) return Response(ResourceSlimSerializer(self.get_object().resources, many=True).data)
def get_resources(self, request, pk): books = ResourceSlimSerializer(self.get_object().resources, many=True) return Response(books.data)