Skip to content

Commit

Permalink
fix: add item_counts to ProjectSerializer for new sidebar design
Browse files Browse the repository at this point in the history
  • Loading branch information
annehaley committed Sep 30, 2024
1 parent 4413524 commit d5db4f1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions uvdat/core/rest/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ProjectSerializer(serializers.ModelSerializer):
owner = serializers.SerializerMethodField('get_owner')
collaborators = serializers.SerializerMethodField('get_collaborators')
followers = serializers.SerializerMethodField('get_followers')
item_counts = serializers.SerializerMethodField('get_item_counts')

def get_center(self, obj):
# Web client expects Lon, Lat
Expand All @@ -53,6 +54,14 @@ def get_followers(self, obj):
users = get_users_with_perms(obj, only_with_perms_in=['follower'])
return [UserSerializer(user).data for user in users.all()]

def get_item_counts(self, obj):
return {
'datasets': obj.datasets.count(),
'regions': obj.derived_regions.count(),
'charts': obj.charts.count(),
'simulations': obj.simulation_results.count(),
}

def to_internal_value(self, data):
center = data.get('default_map_center')
data = super().to_internal_value(data)
Expand Down

0 comments on commit d5db4f1

Please sign in to comment.