From 96670857e986520af56b66e043b599eeb70da7d9 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 15 Nov 2024 19:47:24 +0930 Subject: [PATCH] fix(api): Ensure queryset filters to actual item if pk is defined ref: #248 #385 #388 #389 nofusscomputing/centurion_erp_ui#23 --- app/api/viewsets/common.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/api/viewsets/common.py b/app/api/viewsets/common.py index b8613849f..acc001c1a 100644 --- a/app/api/viewsets/common.py +++ b/app/api/viewsets/common.py @@ -197,8 +197,16 @@ def get_queryset(self): if not self.queryset: - self.queryset = self.model.objects.all() - + queryset = self.model.objects.all() + + if 'pk' in self.kwargs: + + if self.kwargs['pk']: + + queryset = queryset.filter( pk = int( self.kwargs['pk'] ) ) + + self.queryset = queryset + return self.queryset