From 3e86608f89941740fb4f0e58f303b758ff150cdb Mon Sep 17 00:00:00 2001 From: Yurii Purdenko Date: Mon, 2 Dec 2024 15:49:22 +0100 Subject: [PATCH] fix --- bhtom2/bhtom_common/serializers.py | 42 +++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/bhtom2/bhtom_common/serializers.py b/bhtom2/bhtom_common/serializers.py index f3028ac..a5f06a6 100644 --- a/bhtom2/bhtom_common/serializers.py +++ b/bhtom2/bhtom_common/serializers.py @@ -50,21 +50,39 @@ def get_observatory(self, obj): def get_calibration_data(self, obj): + # Fetch the first calibration data record related to the dataproduct + cal = Calibration_data.objects.filter(dataproduct=obj).first() - cal = Calibration_data.objects.get(dataproduct=obj) + # Return empty fields if no calibration data exists + if not cal: return { - 'id': cal.id or "", - 'time_photometry': cal.modified or "", - 'mjd': cal.mjd or "", - 'calib_survey_filter': f"{cal.use_catalog.survey or ''}/{cal.use_catalog.filters or ''}", - 'standardised_to': f"{cal.survey or ''}/{cal.best_filter or ''}" if cal.survey and cal.best_filter else "", - 'magnitude': cal.mag or "", - 'zp': cal.zeropoint or "", - 'scatter': cal.scatter or "", - 'number of datapoints used for calibration': cal.npoints or "", - 'outlier fraction': cal.outlier_fraction or "", - 'matching radius[arcsec]': cal.match_distans or "" + 'id': "", + 'time_photometry': "", + 'mjd': "", + 'calib_survey_filter': "", + 'standardised_to': "", + 'magnitude': "", + 'zp': "", + 'scatter': "", + 'number of datapoints used for calibration': "", + 'outlier fraction': "", + 'matching radius[arcsec]': "" } + + # Return populated data if calibration data exists + return { + 'id': cal.id or "", + 'time_photometry': cal.modified or "", + 'mjd': cal.mjd or "", + 'calib_survey_filter': f"{cal.use_catalog.survey or ''}/{cal.use_catalog.filters or ''}", + 'standardised_to': f"{cal.survey or ''}/{cal.best_filter or ''}" if cal.survey and cal.best_filter else "", + 'magnitude': cal.mag or "", + 'zp': cal.zeropoint or "", + 'scatter': cal.scatter or "", + 'number of datapoints used for calibration': cal.npoints or "", + 'outlier fraction': cal.outlier_fraction or "", + 'matching radius[arcsec]': cal.match_distans or "" + }