按ToManyField的id过滤

时间:2013-12-03 17:06:38

标签: python django tastypie

我有一个看起来像这样的资源:

class CustomerResource(ModelResource):

    locations = fields.ToManyField('device.resources.LocationResource',
            'location_set', null=True)
    current_location = fields.ToOneField('device.resources.LocationResource',
            'current_location', null=True)
    default_location = fields.ToOneField('device.resources.LocationResource',
            'default_location', null=True)

    class Meta:
        queryset = Customer.objects.all()
        resource_name = 'customers'
        validation = CleanedDataFormValidation(form_class=RegistrationForm)
        list_allowed_methods = ['get', 'post']
        detail_allowed_methods = ['get', 'put', 'patch', 'delete']
        authorization = Authorization()
        excludes =['is_superuser', 'is_active', 'is_staff', 'password', 'last_login',]
        filtering = {
            'location': ('exact'),
        }

我想查询API以获取客户列表,这些客户是否在其位置字段中具有特定位置。示例网址如下所示:

localhost/v1/customers/?location=1&format=json

不幸的是,虽然Tastypie认为我当前的过滤方案是有效的,但当我将location参数传递给URL时,它似乎什么都不做。端点返回所有客户的列表。我做错了什么,或者有没有办法扩展过滤以获得我想要的东西?

1 个答案:

答案 0 :(得分:0)

您的ToManyField称为“位置”,而不是“位置”

相关问题