Пример #1
0
 def retrieve(self, request, *args, **kwargs):
     instance = self.get_object()
     serializer = self.get_serializer(instance)
     data = get_serializer_data_to_json(serializer.data)
     data = clean_response_field(data, self.del_fields)
     return CustomBaseJsonResponse(data=data,
                                   code=status.HTTP_200_OK,
                                   msg="Queried successfully.",
                                   status=True)
Пример #2
0
 def destroy(self, request, *args, **kwargs):
     check_model_field(request.data, self.model_name, ck_field='username')
     instance = self.get_object()
     _id = instance.id
     self.perform_destroy(instance)
     logger.info('Delete: {}'.format([{"id": _id}]))
     return CustomBaseJsonResponse(data=[{
         "id": _id
     }],
                                   code=status.HTTP_200_OK,
                                   msg="Deleted successfully.",
                                   status=True)
Пример #3
0
 def create(self, request, *args, **kwargs):
     self.serializer_class = CreateMembersModelSerializer
     serializer = self.get_serializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     self.perform_create(serializer)
     headers = self.get_success_headers(serializer.data)
     logger.info('Create: {}'.format(serializer.data))
     data = get_serializer_data_to_json(serializer.data)
     return CustomBaseJsonResponse(data=data,
                                   code=status.HTTP_201_CREATED,
                                   headers=headers,
                                   msg="Created successfully.",
                                   status=True)
Пример #4
0
    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        page = self.paginate_queryset(queryset)
        if page is not None:
            serializer = self.get_serializer(page, many=True)
            data = get_serializer_data_to_json(serializer.data)
            data = clean_response_field(data, self.del_fields)
            return self.get_paginated_response(data)

        serializer = self.get_serializer(queryset, many=True)
        data = get_serializer_data_to_json(serializer.data)
        data = clean_response_field(data, self.del_fields)
        return CustomBaseJsonResponse(data)
Пример #5
0
    def update(self, request, *args, **kwargs):
        self.serializer_class = UpdateMembersModelSerializer
        partial = kwargs.pop('partial', False)
        instance = self.get_object()
        serializer = self.get_serializer(instance,
                                         data=request.data,
                                         partial=partial)
        serializer.is_valid(raise_exception=True)
        self.perform_update(serializer)

        if getattr(instance, '_prefetched_objects_cache', None):
            instance._prefetched_objects_cache = {}
        logger.info('Update: {}'.format(serializer.data))
        data = get_serializer_data_to_json(serializer.data)
        return CustomBaseJsonResponse(data=data,
                                      code=status.HTTP_200_OK,
                                      msg="Updated successfully.",
                                      status=True)