From 860c7b50e5f2092af0009ac24be64a709a573489 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 10 Sep 2020 14:42:52 +0200 Subject: [PATCH] Filter a consumer by its note id --- apps/note/api/views.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/note/api/views.py b/apps/note/api/views.py index 064f3d1d..ae8bc94e 100644 --- a/apps/note/api/views.py +++ b/apps/note/api/views.py @@ -108,8 +108,9 @@ class AliasViewSet(ReadProtectedModelViewSet): class ConsumerViewSet(ReadOnlyProtectedModelViewSet): queryset = Alias.objects.all() serializer_class = ConsumerSerializer - filter_backends = [SearchFilter, OrderingFilter] + filter_backends = [SearchFilter, OrderingFilter, DjangoFilterBackend] search_fields = ['$normalized_name', '$name', '$note__polymorphic_ctype__model', ] + filterset_fields = ['note'] ordering_fields = ['name', 'normalized_name'] def get_queryset(self): @@ -118,7 +119,7 @@ class ConsumerViewSet(ReadOnlyProtectedModelViewSet): :return: The filtered set of requested aliases """ - queryset = super().get_queryset() + queryset = super().get_queryset().distinct() # Sqlite doesn't support ORDER BY in subqueries queryset = queryset.order_by("name") \ if settings.DATABASES[queryset.db]["ENGINE"] == 'django.db.backends.postgresql' else queryset