diff --git a/app/server/filters.py b/app/server/filters.py index b6976faa..ea8d46d2 100644 --- a/app/server/filters.py +++ b/app/server/filters.py @@ -1,4 +1,4 @@ -from django.db.models import Count +from django.db.models import Count, Q from django_filters.rest_framework import FilterSet, BooleanFilter from .models import Document @@ -9,7 +9,9 @@ class DocumentFilter(FilterSet): seq2seq_annotations__isnull = BooleanFilter(field_name='seq2seq_annotations', method='filter_annotations') def filter_annotations(self, queryset, field_name, value): - queryset = queryset.annotate(num_annotations=Count(field_name)) + queryset = queryset.annotate(num_annotations= + Count(field_name, filter= + Q(**{ f"{field_name}__user": self.request.user}))) should_have_annotations = not value if should_have_annotations: