Skip to content

Commit 660bd18

Browse files
committed
add geographies field to collaborative
1 parent 9bf3c08 commit 660bd18

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

api/types/type_collaborative.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
TypeCollaborativeOrganizationRelationship,
1919
)
2020
from api.types.type_dataset import TypeDataset, TypeTag
21+
from api.types.type_geo import TypeGeo
2122
from api.types.type_organization import TypeOrganization
2223
from api.types.type_sdg import TypeSDG
2324
from api.types.type_sector import TypeSector
@@ -71,6 +72,17 @@ def is_individual_collaborative(self) -> bool:
7172
"""Check if this collaborative is created by an individual user."""
7273
return self.organization is None
7374

75+
@strawberry.field(description="Get geographies associated with this collaborative.")
76+
def geographies(self) -> Optional[List[TypeGeo]]:
77+
"""Get geographies associated with this collaborative."""
78+
try:
79+
queryset = self.geographies.all() # type: ignore
80+
if not queryset.exists():
81+
return []
82+
return TypeGeo.from_django_list(queryset)
83+
except Exception:
84+
return []
85+
7486
@strawberry.field(description="Get datasets associated with this collaborative.")
7587
def datasets(self) -> Optional[List["TypeDataset"]]:
7688
"""Get datasets associated with this collaborative."""

api/types/type_geo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
from strawberry import auto
55

66
from api.models import Geography
7+
from api.types.base_type import BaseType
78

89

910
@strawberry_django.type(Geography)
10-
class TypeGeo:
11+
class TypeGeo(BaseType):
12+
id: auto
1113
name: auto
1214
code: auto
1315
type: auto

0 commit comments

Comments
 (0)