我可以通过如下重写accountviewset的get_object()方法来实现它。
def get_object(self, queryset=None):
"""
Fix - If account has already sent a friend request, show it even if user set
discoverable = False
"""
pk = self.kwargs.get('pk', None)
account = Account.objects.filter(id=pk).first()
if account:
if account.is_friends_with(self.request.user, True):
self.check_object_permissions(self.request, account)
return account
#default handling in case they are not friends
return super(viewsets.GenericViewSet, self).get_object()