class LinguistResource(ModelResource):
class Meta:
model = Linguist
queryset = Linguist.objects.all()
resource_name = 'linguists_by_language'
filtering = {
"language": ('exact', ),
}
是否可以强制使用“语言”过滤器?
如果在GET参数中没有键“language”
,我的目标是引发错误答案 0 :(得分:13)
您可以通过覆盖build_filters:
来捕捉到这一点from tastypie.exceptions import BadRequest
def build_filters(self, filters=None):
if 'language' not in filters:
raise BadRequest("missing language param") # or maybe create your own exception
return super(LinguistResource, self).build_filters(filters)