From c1a96b256abaa7a906ea30a17ddb98947d78c3a0 Mon Sep 17 00:00:00 2001 From: Florian Knappers <73856313+JJFlorian@users.noreply.github.com> Date: Thu, 28 Mar 2024 15:50:35 +0100 Subject: [PATCH] added gmw_well_code to monitoringtube endpoint --- gmw/serializers.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gmw/serializers.py b/gmw/serializers.py index 1b737eb..e5415b4 100644 --- a/gmw/serializers.py +++ b/gmw/serializers.py @@ -31,6 +31,8 @@ def get_linked_gmns(self, obj): class MonitoringTubeSerializer( UrlFieldMixin, RequiredFieldsMixin, serializers.ModelSerializer ): + gmw_well_code = serializers.SerializerMethodField() + class Meta: model = gmw_models.MonitoringTube fields = "__all__" @@ -39,3 +41,9 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) for field in self.fields.values(): field.required = True + + def get_gmw_well_code(self, obj): + try: + return gmw_models.GMW.objects.get(uuid=obj.gmw.uuid).well_code + except ObjectDoesNotExist: + return None