我要在tastypi的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,
}
我在底部foreignkey上设置了“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,
}
目前没有回答
相关问题 更多 >
编程相关推荐