From 3fe2d900a282116c30ab23ed6813d5224317da1c Mon Sep 17 00:00:00 2001 From: k1o0 Date: Fri, 12 Apr 2024 16:32:34 +0300 Subject: [PATCH] Include reference_weight_pct and zscore_weight_pct in water restriction serializers --- alyx/actions/views.py | 5 ++++- alyx/subjects/serializers.py | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/alyx/actions/views.py b/alyx/actions/views.py index bec3461f..2ecd7287 100644 --- a/alyx/actions/views.py +++ b/alyx/actions/views.py @@ -457,7 +457,10 @@ def get(self, request, format=None, nickname=None): end_date = request.query_params.get('end_date', None) subject = Subject.objects.get(nickname=nickname) records = subject.water_control.to_jsonable(start_date=start_date, end_date=end_date) - data = {'subject': nickname, 'implant_weight': subject.implant_weight, 'records': records} + data = {'subject': nickname, 'implant_weight': subject.implant_weight, + 'reference_weight_pct': subject.water_control.reference_weight_pct, + 'zscore_weight_pct': subject.water_control.zscore_weight_pct, + 'records': records} return Response(data) diff --git a/alyx/subjects/serializers.py b/alyx/subjects/serializers.py index b6a2877d..e9f954bf 100644 --- a/alyx/subjects/serializers.py +++ b/alyx/subjects/serializers.py @@ -28,10 +28,18 @@ def get_reference_weight(self, obj): def get_last_water_restriction(self, obj): return obj.water_control.water_restriction_at() + def get_reference_weight_pct(self, obj): + return obj.water_control.reference_weight_pct + + def get_zscore_weight_pct(self, obj): + return obj.water_control.zscore_weight_pct + expected_water = serializers.SerializerMethodField() remaining_water = serializers.SerializerMethodField() reference_weight = serializers.SerializerMethodField() last_water_restriction = serializers.SerializerMethodField() + reference_weight_pct = serializers.SerializerMethodField() + zscore_weight_pct = serializers.SerializerMethodField() class WaterRestrictedSubjectListSerializer(_WaterRestrictionBaseSerializer): @@ -42,6 +50,8 @@ class Meta: 'remaining_water', 'reference_weight', 'last_water_restriction', + 'reference_weight_pct', + 'zscore_weight_pct' ) lookup_field = 'nickname'