diff --git a/map/serializers.py b/map/serializers.py index 03dd912..884d3dd 100644 --- a/map/serializers.py +++ b/map/serializers.py @@ -6,29 +6,21 @@ class CommunityAreaSerializer(serializers.ModelSerializer): class Meta: model = CommunityArea - fields = ["name", "num_permits"] + fields = ["area_id","name", "num_permits"] num_permits = serializers.SerializerMethodField() def get_num_permits(self, obj): - """ - TODO: supplement each community area object with the number - of permits issued in the given year. + + year = self.context.get("year") - e.g. The endpoint /map-data/?year=2017 should return something like: - [ - { - "ROGERS PARK": { - area_id: 17, - num_permits: 2 - }, - "BEVERLY": { - area_id: 72, - num_permits: 2 - }, - ... - } - ] - """ - - pass + if year: + count = RestaurantPermit.objects.filter( + community_area_id=str(obj.area_id), + issue_date__year=year + ).count() + return count + return 0 + + + # \ No newline at end of file diff --git a/map/static/js/RestaurantPermitMap.js b/map/static/js/RestaurantPermitMap.js index 57f8ea0..0226135 100644 --- a/map/static/js/RestaurantPermitMap.js +++ b/map/static/js/RestaurantPermitMap.js @@ -6,7 +6,7 @@ import "leaflet/dist/leaflet.css" import RAW_COMMUNITY_AREAS from "../../../data/raw/community-areas.geojson" -function YearSelect({ setFilterVal }) { +function YearSelect({ filterVal, setFilterVal }) { // Filter by the permit issue year for each restaurant const startYear = 2026 const years = [...Array(11).keys()].map((increment) => { @@ -28,6 +28,7 @@ function YearSelect({ setFilterVal }) {