Пример #1
0
    def add_item(self, request, pk, obj_serializer):
        collection = get_collection(pk, request, mode='api')

        if not owner_or_contrib(request, collection):
            self.permission_denied(request)

        obj = obj_serializer.Meta.model(collection=collection)
        serializer = obj_serializer(data=request.data,
                                    instance=obj,
                                    context={'request': request})

        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Пример #2
0
    def add_item(self, request, pk, obj_serializer):
        collection = get_collection(pk, request, mode='api')

        if not owner_or_contrib(request, collection):
            self.permission_denied(request)

        obj = obj_serializer.Meta.model(collection=collection)
        serializer = obj_serializer(data=request.data,
                                    instance=obj,
                                    context={'request': request})

        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data,
                            status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)