我尝试使用OneToField字段过滤ressource。
我想要通过此url给出与任务secure_key相关的最喜欢的相关:
/喜爱/ API /所有/?task__secure_key = sdsd900kljhiu987bbhU
和tastypie返回:
{"error": "The 'secure_key' field does not allow filtering."}
以下是我的文件:
喜爱/ api.py
class FavoriteRessource(ModelResource):
task = fields.ToOneField('task.api.TaskResource', attribute='task', full=True)
user = fields.ToOneField('foruser.api.UserRessource', attribute='user', full=True)
class Meta:
queryset = Favorite.objects.all()
resource_name = 'all'
excludes = ['id']
allowed_methods = ['get', 'post']
include_resource_uri = False
authentication = BaseAuthentication()
authorization = Authorization()
filtering = {
'task': ALL_WITH_RELATIONS,
}
任务/ api.py
class TaskResource(ModelResource):
city = fields.ToOneField(AppCityRessource, attribute='city', null=True, full=True)
category = fields.ToOneField(TaskCategoryResource, attribute='category', null=True, full=True)
user = fields.ToOneField(UserRessource, attribute='user', null=True, full=True)
skill = fields.ToManyField(SkillRessource, attribute='skill', full=True)
class Meta:
#queryset = Task.objects.filter(active=True, admin_active=True, skill_active=True)
queryset = Task.objects.all()
resource_name = 'all'
excludes = ['active', 'admin_active', 'skill_active', 'participant_history']
allowed_methods = ['get', 'post', 'put', 'delete']
always_return_data = True
include_resource_uri = False
authentication = BaseAuthentication()
authorization = Authorization()
filtering = {
'secure_key': ALL,
}
我的错误在哪里?