Пример #1
0
    def put(self, request, pk, format=None):
        group = self.get_object(pk)
        serializer = GroupSerializer(group, data=request.data)
        if serializer.is_valid():
            serializer.save()
            logger.debug('Updated data of Group object with id ' + str(pk))
            return Response(serializer.data)

        logger.error('Error on data update for Group object with id ' + str(pk))
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Пример #2
0
    def __post(self, request, format=None):
        """
        Method used to create a new Group object.
        """
        serializer = GroupSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            logger.debug('Created a new Group object')
            return Response(serializer.data, status=status.HTTP_201_CREATED)

        logger.error('Error on creation of new Group object')
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)