嗨,我在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_type (来自上面的资源)。但是当我作为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相同的值,而不是缩小我的搜索范围。我对资源或品味有点陌生。伙计们这是怎么了?有什么想法吗?提前谢谢。
发布于 2016-05-22 13:18:57
试试这个:
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=1https://stackoverflow.com/questions/37370225
复制相似问题