def put(self, request, pk): address = Address.objects.get(id=pk) data = request.data serializer = AddressTitleSerializer(instance=address, data=data) serializer.is_valid(raise_exception=True) serializer.save() return Response(serializer.data)
def title(self, request, pk=None): '''修改标题''' address = self.get_object() serializer = AddressTitleSerializer() serializer.is_valid(raise_exception=True) serializer.save() return Response({'message': 'OK'}, status=status.HTTP_200_OK)
def title(self, request, *args, **kwargs): """修改标题""" address = self.get_object() serializer = AddressTitleSerializer(instance=address, data=request.data) serializer.is_valid(raise_exception=True) serializer.save() return Response(serializer.data)
def title(self, request, pk=None): query = Address.objects.get(pk=pk) s = AddressTitleSerializer(query, data=request.data) s.is_valid(raise_exception=True) s.save() return Response(s.data)
def title(self, request, pk=None, address_id=None): '''修改标题''' address = self.get_object() serializer = AddressTitleSerializer(instance=address, data=request.data) # 地址标题的序列化器对象 serializer.is_valid(raise_exception=True) serializer.save() return Response(serializer.data)
def title(self, request, pk=None): """ 修改标题 """ address = self.get_object() serializer = AddressTitleSerializer(address, data=request.data) serializer.is_valid(raise_exception=True) serializer.save() return Response(serializer.data)
def title(self, request, pk=None): """ 修改标题 """ # 从用户的地址中根据pk获取对应地址 address = self.get_object() # 获取title并进行校验 serializer = AddressTitleSerializer(instance=address, data=request.data) serializer.is_valid(raise_exception=True) # 设置用户地址的标题 serializer.save() return Response(serializer.data)
def title(self, request, pk): """ 1.根据pk获取对应的地址数据 2.获取title并进行校验 3.设置地址标题 4.返回应答 """ # 1.根据pk获取对应的地址数据 address = self.get_object() # 2.获取title并进行校验 serializer = AddressTitleSerializer(address, data=request.data) serializer.is_valid(raise_exception=True) # 3.设置地址标题 serializer.save() # 4.返回应答 return Response(serializer.data)
def title(self, request, pk): """ 修改指定地址标题 1.根据pk查询指定的地址 2.获取title参数并校验(title必传) 3.修改指定地址的标题并更新数据库 4.返回应答,设置标题成功 """ address = self.get_object() serializer = AddressTitleSerializer(address, data=request.data) serializer.is_valid(raise_exception=True) serializer.save() return Response(serializer.data)
def title(self, request, pk): """ 修改指定的地址标题: 1. 根据pk获取指定的地址数据 2. 获取title并进行校验(title必传) 3. 保存修改地址的标题 4. 返回应答 """ # 1. 根据pk获取指定的地址数据 address = self.get_object() # 2. 获取title并进行校验(title必传) serializer = AddressTitleSerializer(address, data=request.data) serializer.is_valid(raise_exception=True) # 3. 保存修改地址的标题(update) serializer.save() # 4. 返回应答 return Response(serializer.data)
def title(self, request, pk): """ # 修改指定地址标题 1.根据pk查询指定的diz 2.获取title参数并校验(title必传) 3.修改指定地址的标题并更新数据库 4.返回应答,设置标题成功 """ # 1.根据pk查询指定的diz address = self.get_object() # 2.获取title参数并校验(title必传) serializer = AddressTitleSerializer(address, data=request.data) serializer.is_valid(raise_exception=True) title = serializer.validated_data['title'] # 3.修改指定地址的标题并更新数据库 serializer.save() # 4.返回应答,设置标题成功 return Response(serializer.data)