次のように、Tastypie リソースに行レベルの承認を追加しました。
from tastypie.exceptions import ImmediateHttpResponse
from tastypie.http import HttpUnauthorized
class MyResource(ModelResources):
...
def is_authorized(self, request, object=None):
super(MyResource, self).is_authorized(request, object)
if object and (object.user != request.user):
raise ImmediateHttpResponse(response=HttpUnauthorized())
簡潔にするために、通常のインポートを省略し、質問に関連するインポートのみを指定しました。
私の質問は、インポートせずにオーバーライドするよりクリーンな方法はありますis_authorized
か? これらは実装の詳細であるように思われ、単純にorを返すことができるはずです。ImmediateHttpResponse
HttpUnauthorized
True
False