0

鉴于:

class CheckResource(ModelResource):
    user = fields.ForeignKey(UserResource, 'user', full=True)
    venue = fields.ForeignKey(VenueResource, 'venue', full=False)
    items = fields.ToManyField('checks.api.CheckToItemResource',
                               'checktoitem_set',
                               related_name='checktoitem',
                               full=True,
                               null=True,
                               blank=True
                               )
    payments = fields.ToManyField('payments.api.PaymentResource',
                                  'payment_set',
                                  related_name='check', 
                                  full=True,
                                  null=True,
                                  blank=True
                                  )
    authorizations = fields.ToManyField('authorizenet.api.AuthorizenetResource',
                                        'response_set',
                                        related_name='check',
                                        full=True,
                                        null=True,
                                        blank=True
                                        )

    class Meta:
        queryset = Check.objects.filter(checktoitem__is_void=False)
        allowed_methods = ['get', 'post', 'put']
        include_resource_uri = False
        always_return_data = True
        ordering = ['number', 'is_closed']
        filtering = {
            'slug': 'exact',
            'checktoitem': ALL
        }


class CheckToItemResource(ModelResource):
    user = fields.ForeignKey(UserResource, 'user', full=True)
    venue = fields.ForeignKey(VenueResource, 'venue', full=False)
    check = fields.ForeignKey(CheckResource, 'check', full=False)
    item = fields.ForeignKey(ItemResource, 'item', full=True)
    parent_item = fields.ForeignKey(ItemResource, 'parent_item', full=False, null=True)

    class Meta:
        queryset = CheckToItem.objects.filter(is_void=False)
        allowed_methods = ['get', 'post', 'put']
        include_resource_uri = False
        always_return_data = True
        filtering = {
            'check': 'exact',
            'is_void': ALL
        }
        ordering = ['created']

请注意,我试图仅检索 is_void=False 的 checktoitem 记录。但是,将返回所有记录(不仅仅是未作废的记录)。有什么帮助吗?我尝试在几个地方添加过滤器,但没有任何效果。

4

1 回答 1

0

你能展示你提出的要求吗?请求而不是代码中可能有错误。

使用 python requests 模块的示例请求:

import requests
r = request.get('http://localhost:8000/api/checktoitem/?is_void=False', auth=('user', 'pass'), headers={'content-type': 'application/json'})
于 2013-06-10T14:16:41.257 回答