鉴于:
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 记录。但是,将返回所有记录(不仅仅是未作废的记录)。有什么帮助吗?我尝试在几个地方添加过滤器,但没有任何效果。