From 7d641e95d7c7ec9b897622adbf383b7c1fc4b09e Mon Sep 17 00:00:00 2001 From: i701 Date: Sat, 28 Jun 2025 10:25:46 +0500 Subject: [PATCH] Enhance DeviceListCreateAPIView to allow admin users to access all devices based on query parameter --- devices/views.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/devices/views.py b/devices/views.py index 45415c9..bf9f4cb 100644 --- a/devices/views.py +++ b/devices/views.py @@ -30,10 +30,14 @@ class DeviceListCreateAPIView( def list(self, request, *args, **kwargs): queryset = self.filter_queryset(self.get_queryset()) - - if request.user.is_authenticated and not getattr( - request.user, "is_admin", False + all_devices = request.query_params.get("all_devices", None) + if ( + request.user.is_authenticated + and getattr(request.user, "is_admin", False) + and all_devices ): + pass + else: queryset = queryset.filter(user=request.user) page = self.paginate_queryset(queryset)