4

我有两个这样的模型:

class CompanyResource(ModelResource):
    class Meta:
        queryset = Company.objects.all()
        fields = ['title', 'latitude', 'longitude']
        resource_name = 'company'
        filtering = {
            'latitude': ALL,
            'longitude': ALL
        }

class EventResource(ModelResource):
    company = fields.ToOneField(CompanyResource, 'company', full=True)
    class Meta:
        fields = ['title', 'company']
        queryset = Event.objects.all()
        resource_name = 'event'
        filtering = {
            'company': ALL_WITH_RELATIONS
        }

然后我尝试访问/api/v1/event/?format=json&company_latitude__within=2,3/api/v1/event/?format=json&company_latitude__lt=1未按纬度过滤:

{
    "meta": {
        "limit": 20, 
        "next": "/api/v1/event/?offset=20&limit=20&format=json", 
        "offset": 0, 
        "previous": null, 
        "total_count": 329
    }, 
    "objects": [
        {
            "company": {
                "latitude": "1.30521100000000", 
                "longitude": "103.81116299999996", 
                "resource_uri": ""
            }, 
            "resource_uri": "/api/v1/event/16/", 
            "title": "50% off at Infusion@Dempsey, $50 for $100 worth of Fine Dining"
        }
    ]
}

我怎样才能使这项工作?

4

1 回答 1

4

哦,这是因为两件事。我不能field__within在 Django 中做(为什么我会这么想?)而且应该是/api/v1/event/?format=json&company__latitude__lt=2.

于 2012-09-14T21:10:31.950 回答