序列化器(Serializers)踩坑記錄

夜久听山雨發表於2024-06-05

1、data資料不能加'.values()'

    def listParticulars(self, request, *args, **kwargs):
        particulars = xmind_particulars.objects.all()#不能加values()
        serializer = ParticularsSerializer(particulars, many=True)
        return APIRespones('1000', 'ok', True, serializer.data)
    def queryParticulars(self, request, **kwargs):
        particulars_name = request.data["particulars_name"]
        module_second_id = request.data["module_second_id"]
        if module_second_id != '' and particulars_name != '':
            q1 = Q(module_second_id=module_second_id)
            q2 = Q(particulars_name=particulars_name)
            data = xmind_particulars.objects.filter(q1, q2) #不能加values()
            serializer = ParticularsSerializer(instance=data, many=True)
        return APIRespones('1000', 'ok', True, serializer.data)

相關文章