diff --git a/backend-project/small_eod/autocomplete/tests/test_views.py b/backend-project/small_eod/autocomplete/tests/test_views.py index b6ec69d40..0f7991b9c 100644 --- a/backend-project/small_eod/autocomplete/tests/test_views.py +++ b/backend-project/small_eod/autocomplete/tests/test_views.py @@ -109,11 +109,11 @@ def test_suggests_related(self): # Match all - the related institution should appear at the top. resp = self.get_response_for_query("institution", case=case.id) - self.assertEqual(resp.data['results'][0]['id'], institution_b.id) + self.assertEqual(resp.data["results"][0]["id"], institution_b.id) # Match a specific, non-related item. The related institution should not be present. resp = self.get_response_for_query("institution_a", case=case.id) - self.assertEqual([r['id'] for r in resp.data['results']], [institution_a.id]) + self.assertEqual([r["id"] for r in resp.data["results"]], [institution_a.id]) class TagAutocompleteViewSetTestCase(ReadOnlyViewSetMixin, SearchQueryMixin, TestCase): diff --git a/backend-project/small_eod/autocomplete/views.py b/backend-project/small_eod/autocomplete/views.py index d9a49c87f..34f44a9cd 100644 --- a/backend-project/small_eod/autocomplete/views.py +++ b/backend-project/small_eod/autocomplete/views.py @@ -1,5 +1,5 @@ -from django_filters.rest_framework import DjangoFilterBackend from django.db import models +from django_filters.rest_framework import DjangoFilterBackend from rest_framework import viewsets from ..administrative_units.filterset import AdministrativeUnitFilterSet @@ -33,6 +33,7 @@ UserAutocompleteSerializer, ) + class AdministrativeUnitAutocompleteViewSet(viewsets.ReadOnlyModelViewSet): queryset = AdministrativeUnit.objects.only("id", "name").all() serializer_class = AdministrativeUnitAutocompleteSerializer @@ -89,7 +90,7 @@ class InstitutionAutocompleteViewSet(viewsets.ReadOnlyModelViewSet): def get_queryset(self): req = self.request - related_case_id = req.GET.get('case', None) + related_case_id = req.GET.get("case", None) if related_case_id is None: qs = Institution.objects.all() else: @@ -98,9 +99,9 @@ def get_queryset(self): related=models.Case( models.When(case=related_case_id, then=True), default=False, - output_field=models.BooleanField() + output_field=models.BooleanField(), ) - ).order_by('-related') + ).order_by("-related") return qs.only("id", "name")