From 970d6c0307bd83aa2fc39ead6b2fd463e0ed1226 Mon Sep 17 00:00:00 2001 From: Corban-Lee Jones Date: Tue, 16 Jan 2024 13:53:05 +0000 Subject: [PATCH] ticket API changed to detect "__in" key --- apps/api/views.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/api/views.py b/apps/api/views.py index f9f6082..0007fa4 100644 --- a/apps/api/views.py +++ b/apps/api/views.py @@ -42,7 +42,7 @@ class TicketListApiView(APIView): pagination_class = TicketPaginiation ALLOWED_FILTERS = ( - "uuid__in", "priority__in", "tags__in", "author__department__in", "search" + "uuid__in", "priority", "tags__in", "author__department", "search" ) MATCHER_MAP = { "contains": lambda k, v: {k: v[0]}, @@ -100,6 +100,8 @@ class TicketListApiView(APIView): for key, values in request.GET.lists(): key = key.removesuffix("[]") + print(key, values) + if key not in self.ALLOWED_FILTERS: raise KeyError(key) @@ -116,6 +118,10 @@ class TicketListApiView(APIView): if "all" in values: continue + if not key.endswith("__in"): + queryset = queryset.filter(Q(**{key: values})) + continue + for value in values: filter_kwargs = {key: [value]} queryset = queryset.filter(Q(**filter_kwargs))