def my_destroy(self, request, *args, **kwargs): # 获取单个的 model对象 book_obj = self.get_object() print("book_obj", book_obj, type(book_obj)) if not book_obj: return MYResponse(500, "删除失败") book_obj.is_delete = True book_obj.save() return MYResponse(200, "删除成功")
def get(self, request, *args, **kwargs): if "id" in kwargs: response = self.retrieve(request, *args, **kwargs) else: response = self.list(request, *args, **kwargs) return MYResponse(results=response.data, data_message="查询成功")
def my_create(self, request, *args, **kwargs): request_data = request.data print(request_data) # TODO 与数据库中对象的数据做匹配 完成业务逻辑后返回结果 return MYResponse(results="OK")
def patch(self, request, *args, **kwargs): response = self.partial_update(request, *args, **kwargs) return MYResponse(results=response.data)
def put(self, request, *args, **kwargs): response = self.update(request, *args, **kwargs) return MYResponse(results=response.data)
def get(self, request, *args, **kwargs): book_list = Book.objects.filter(is_delete=False).all() book_ser = serializers.BookModelSerializer(book_list, many=True) book_data = book_ser.data return MYResponse(results=book_data)