ticket API changed to detect "__in" key

This commit is contained in:
Corban-Lee Jones 2024-01-16 13:53:05 +00:00
parent db8206b1bd
commit 970d6c0307

View File

@ -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))