diff --git a/apis_ontology/api/views.py b/apis_ontology/api/views.py index 57437cc..1319567 100644 --- a/apis_ontology/api/views.py +++ b/apis_ontology/api/views.py @@ -209,10 +209,14 @@ def get_queryset(self): ) ) - expression_publisher = Organisation.objects.filter( - triple_set_from_subj__obj_id=OuterRef("pk"), - triple_set_from_subj__prop__name_reverse__in=["has publisher"], - ).values("name") + expression_publisher = ( + Organisation.objects.filter( + triple_set_from_subj__obj_id=OuterRef("pk"), + triple_set_from_subj__prop__name_reverse__in=["has publisher"], + ) + .distinct() + .values("name") + ) expression_places = ( Place.objects.filter( @@ -228,7 +232,7 @@ def get_queryset(self): triple_set_from_obj__subj_id=OuterRef("pk"), triple_set_from_obj__prop__name_reverse__in=["realises"], ).annotate( - publisher=Subquery(expression_publisher[:1]), + publisher=Subquery(expression_publisher), places=ArraySubquery(expression_places), ) ).values( @@ -300,13 +304,17 @@ def get_queryset(self): ) ) - expression_publisher = Organisation.objects.filter( - triple_set_from_subj__obj_id=OuterRef("pk"), - triple_set_from_subj__prop__name_reverse__in=["has publisher"], - ).values( - json=JSONObject( - id="id", - name="name", + expression_publisher = ( + Organisation.objects.filter( + triple_set_from_subj__obj_id=OuterRef("pk"), + triple_set_from_subj__prop__name_reverse__in=["has publisher"], + ) + .distinct() + .values( + json=JSONObject( + id="id", + name="name", + ) ) ) @@ -339,7 +347,7 @@ def get_queryset(self): triple_set_from_obj__subj_id=OuterRef("pk"), triple_set_from_obj__prop__name_reverse__in=["realises"], ).annotate( - publisher=Subquery(expression_publisher[:1]), + publisher=Subquery(expression_publisher), places=ArraySubquery(expression_places), ) ).values(