Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在资源中搜索嵌套值(tastypie json)_Python_Json_Django_Tastypie_Jsonresponse - Fatal编程技术网

Python 如何在资源中搜索嵌套值(tastypie json)

Python 如何在资源中搜索嵌套值(tastypie json),python,json,django,tastypie,jsonresponse,Python,Json,Django,Tastypie,Jsonresponse,您好,我在respurces.py文件中有以下资源 class SodResource(ModelResource): class Meta: queryset = Sod.objects.all().order_by('-rank') filtering = {'sod_type': ALL, 'generic_value': ALL} class DeptBpResource(ModelResource): sod_setting = f

您好,我在respurces.py文件中有以下资源

class SodResource(ModelResource):

    class Meta:
        queryset = Sod.objects.all().order_by('-rank')
        filtering = {'sod_type': ALL, 'generic_value': ALL}


class DeptBpResource(ModelResource):
    sod_setting = fields.ToManyField(SodResource, 'sod',  null=True, full=True)

    class Meta:
        queryset = Dept_Bp.objects.all()
        filtering = {
                'dept_name': ALL,
                'bp_name': ALL,
            }
我可以搜索
http://10.85.87.116:8000/fmea/api/v1/deptbp/?format=json&dept_name=DEQP&bp_name=Kaizen
。但我的目标是能够搜索
sod\u类型
(来自上述资源)。但当我搜索为
http://10.85.87.116:8000/fmea/api/v1/deptbp/?format=json&dept_name=DEQP&bp_name=Kaizen&sod_type=1
它只是返回与
http://10.85.87.116:8000/fmea/api/v1/deptbp/?format=json&dept_name=DEQP&bp_name=Kaizen
没有缩小我的搜索范围。我对资源或tastypie有点陌生。伙计们,这里怎么了?有什么想法吗?提前谢谢

试试这个:

class SodResource(ModelResource):

    class Meta:
        queryset = Sod.objects.all().order_by('-rank')
        filtering = {'sod_type': ALL, 'generic_value': ALL}


class DeptBpResource(ModelResource):
    sod_setting = fields.ToManyField(SodResource, 'sod',  null=True, full=True)

    class Meta:
        queryset = Dept_Bp.objects.all()
        filtering = {
            'dept_name': ALL,
            'bp_name': ALL,
            'sod_setting': ALL_WITH_RELATIONS
        }
在你的网址上。您可以这样做:

http://10.85.87.116:8000/fmea/api/v1/deptbp/?format=json&dept_name=DEQP&bp_name=Kaizen&sod_setting__type=1