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