我正在尝试向viewset.ModelViewSet的视图类添加一个函数,以便当用户发出补丁请求时,它返回值并更改属性 . 因此,例如,如果我像身体一样制作补丁,那么{key:food,value:“coffee”}如果数据库中的更改成功,则响应应为200 body:{food:“coffee”}我该怎么办这个?提前致谢 .

class MerchantProfileViewSet(viewsets.ModelViewSet):'''用于列出/检索/更新/删除当前商家的配置文件的视图集'''serializer_class = MerchantProfileSerializer permission_classes =(IsMerchantAndAuthenticated,)

def get_queryset(self):
    if len(MerchantProfile.objects.filter(user=self.request.user)) > 0:
        merchant_profile = MerchantProfile.objects.get(
            user=self.request.user)
        if merchant_profile.merchant:
            return MerchantProfile.objects.filter(merchant=merchant_profile.merchant)
    return None

@action(methods=['get'], detail=False)
def current(self, request):
    '''
    An endpoint for retrieving the current merchant profile data
    '''
    if len(MerchantProfile.objects.filter(user=request.user)) > 0:
        merchant_profile = MerchantProfile.objects.get(
            user=self.request.user)
        if merchant_profile:
            serializer = MerchantProfileSerializer(merchant_profile)
            return Response(data=serializer.data)

    return Response(data='User is not currently associated with any merchant profiles', status=status.HTTP_404_NOT_FOUND)