如何检查权限&在tastypie上授权一个ForeignKey

时间:2015-06-23 10:12:58

标签: python django rest tastypie

我将在tastypie的ModelResource上授权一个ForeignKey。我有底层资源,如果用户没有客户许可," RepairRequestResource"应该为客户ForeignKey返回带有空对象的json。什么是最好的方法?

class RepairRequestResource(ModelResource):
    customer = fields.ForeignKey(CustomerResource, 'customer', full=True)
    class Meta:
        queryset = RepairRequest.objects.all()
        resource_name = 'repair_request'
        authorization = DjangoAuthorization()
        authentication = MultiAuthentication(BasicAuthentication(), SessionAuthentication())
        always_return_data = True
        paginator_class = Paginator
        list_allowed_methods = ['get', 'post', 'put', 'delete']
        filtering = {
            "registerDate": ['gte', 'lte'],
            "deliveredDate": ['gte', 'lte'],
            "customer": ALL_WITH_RELATIONS,
            "id": ALL,
            "query": ALL,
        }

我设置" CustomAuthorization"的自定义授权。在底部的外键上,但是" CustomAuthorization"将不会处理" RepairRequestResource":

class CustomerResource(ModelResource):
    class Meta:
        queryset = Customer.objects.all()
        resource_name = 'customer'
        authorization = CustomAuthorization()
        authentication = MultiAuthentication(BasicAuthentication(), SessionAuthentication())
        always_return_data = True
        list_allowed_methods = ['get', 'post', 'put', 'delete']
        filtering = {
            "name": ALL,
            "id": ALL,
            "family": ALL,
            "gender": ALL,
            "cellPhone": ALL,
            "phone": ALL,
            "company": ALL,
            "address": ALL,
            "email": ALL,
        }

0 个答案:

没有答案