过滤错误:查询不允许超过一级深度 [英] Filtering Error: Lookups are not allowed more than one level deep
本文介绍了过滤错误:查询不允许超过一级深度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从四周看别人在做什么,这应该是有效的,但我错了一句话:
From looking around at what others are doing this should be working, but I an error saying:
查找不允许超过照片字段中的一级。
Lookups are not allowed more than one level deep on the 'photos' field.
这是我有的代码。我已经尝试了一些轻微的变化,我如何设置,但我没有运气。
Here is the code that I have. I've tried a few slight variations with how I set things up but I've had no luck.
class CollectionResource(ModelResource):
photos = fields.ToManyField('photoproject.apps.kit.api.PhotoResource', 'photo_set', null=True, full=True)
class Meta:
authorization = Authorization()
resource_name = 'collection'
queryset = Collection.objects.all()
filtering = {
'name': ['exact'],
'photos': ALL
}
class PhotoResource(ModelResource):
collection = fields.ToOneField(CollectionResource, 'collection')
class Meta:
authorization = Authorization()
resource_name = 'photo'
queryset = Photo.objects.all()
filtering = {
'id': ALL_WITH_RELATIONS
}
而且我试图查询是:
/api/v1/collection/?photos__id=2
推荐答案
根据 StackOverflow answer ,尝试将ALL更改为ALL_WITH_RELATIONS照片:
Per this StackOverflow answer, try changing ALL to ALL_WITH_RELATIONS for "photos":
class CollectionResource(ModelResource):
photos = fields.ToManyField('photoproject.apps.kit.api.PhotoResource', 'photo_set', null=True, full=True)
class Meta:
authorization = Authorization()
resource_name = 'collection'
queryset = Collection.objects.all()
filtering = {
'name': ['exact'],
'photos': ALL_WITH_RELATIONS
}
这篇关于过滤错误:查询不允许超过一级深度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文