From c6603e8aa798400128410ed402b3af698add6d33 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 10 Sep 2020 14:37:11 +0200 Subject: [PATCH] Add more filters in the API --- apps/note/api/views.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/note/api/views.py b/apps/note/api/views.py index a478e7ff..1338ef73 100644 --- a/apps/note/api/views.py +++ b/apps/note/api/views.py @@ -1,5 +1,6 @@ # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later + from django.conf import settings from django.db.models import Q from django.core.exceptions import ValidationError @@ -56,8 +57,9 @@ class AliasViewSet(ReadProtectedModelViewSet): """ queryset = Alias.objects.all() serializer_class = AliasSerializer - filter_backends = [SearchFilter, OrderingFilter] + filter_backends = [SearchFilter, DjangoFilterBackend, OrderingFilter] search_fields = ['$normalized_name', '$name', '$note__polymorphic_ctype__model', ] + filterset_fields = ['note'] ordering_fields = ['name', 'normalized_name'] def get_serializer_class(self): @@ -179,8 +181,11 @@ class TransactionViewSet(ReadProtectedModelViewSet): """ queryset = Transaction.objects.order_by("-created_at").all() serializer_class = TransactionPolymorphicSerializer - filter_backends = [SearchFilter] + filter_backends = [SearchFilter, DjangoFilterBackend, OrderingFilter] + filterset_fields = ["source", "source_alias", "destination", "destination_alias", "quantity", + "polymorphic_ctype", "amount", "created_at", ] search_fields = ['$reason', ] + ordering_fields = ['created_at', 'amount'] def get_queryset(self): user = self.request.user