합리적인 해결책은 동일한 모델에 대해 2 개의 별도 리소스를 사용하는 것입니다. 하나는 독립 실행 형 리소스로 사용되고 두 번째는 서로 다른 권한 부여 규칙을 사용하여 이벤트 내부의 참조로 사용됩니다.
class LocationAuthorization(Authorization):
# [...]
def create_detail(self, object_list, bundle):
if '/api/v1/event/' == bundle.request.path:
return True
else:
return False
# [...]
class LocationResource():
# [...]
class Meta:
serializer = Serializer(formats=['json'])
queryset = Location.objects.all()
resource_name = 'location'
authorization = LocationAuthorization()
# [...]
그것은 물론 당신이 할 수 있도록 좋아하는 자원의 경로를 하드 코딩 할 의무가
/액세스를 허용 : 나는 비트 해키 때문에 덜 호의를 오전
class LocationLimitedResource(ModelResource):
# ...
class Meta:
serializer = Serializer(formats=['json'])
queryset = Location.objects.all()
resource_name = 'location_limited'
allowed_methods = ['get']
always_return_data = True
authentication = ApiKeyAuthentication()
authorization = LocationAuthorization()
# ...
class LocationResource(LocationLimitedResource):
class Meta(LocationLimitedResource.Meta):
allowed_methods = ['get', 'post', 'put', 'delete']
resource_name = 'location'
class EventResource(ModelResource):
location = fields.ForeignKey(LocationResource, 'location', full=True)
class Meta:
serializer = Serializer(formats=['json'])
queryset = Event.objects.all()
resource_name = 'event'
allowed_methods = ['get', 'post']
always_return_data = True
authentication = ApiKeyAuthentication()
authorization = EventAuthorization()
jobs_api = Api(api_name='v1')
jobs_api.register(LocationLimitedResource())
jobs_api.register(LocationResource())
jobs_api.register(EventResource())
다른 방법은 이것이다 . 잠시 후 아키텍처에 대해 자연스럽지 않은데 그 규칙을 잊을 수 있습니다. 또한 API의 문서화 및 자체 발견이 더 어려워집니다.