Use pre-defined queryset by default in API views

This commit is contained in:
Yohann D'ANELLO 2020-09-04 16:02:42 +02:00
parent c03c18e93a
commit f71fb1fa81
1 changed files with 2 additions and 2 deletions

View File

@ -26,7 +26,7 @@ class ReadProtectedModelViewSet(ModelViewSet):
def get_queryset(self): def get_queryset(self):
user = self.request.user user = self.request.user
get_current_session().setdefault("permission_mask", 42) get_current_session().setdefault("permission_mask", 42)
return self.model.objects.filter(PermissionBackend.filter_queryset(user, self.model, "view")).distinct() return self.queryset.filter(PermissionBackend.filter_queryset(user, self.model, "view")).distinct()
class ReadOnlyProtectedModelViewSet(ReadOnlyModelViewSet): class ReadOnlyProtectedModelViewSet(ReadOnlyModelViewSet):
@ -41,7 +41,7 @@ class ReadOnlyProtectedModelViewSet(ReadOnlyModelViewSet):
def get_queryset(self): def get_queryset(self):
user = self.request.user user = self.request.user
get_current_session().setdefault("permission_mask", 42) get_current_session().setdefault("permission_mask", 42)
return self.model.objects.filter(PermissionBackend.filter_queryset(user, self.model, "view")).distinct() return self.queryset.filter(PermissionBackend.filter_queryset(user, self.model, "view")).distinct()
class UserViewSet(ReadProtectedModelViewSet): class UserViewSet(ReadProtectedModelViewSet):