diff --git a/api/mixins.py b/api/mixins.py index c21b2be..3b015d7 100644 --- a/api/mixins.py +++ b/api/mixins.py @@ -44,3 +44,10 @@ def to_representation(self, instance): if url_field: data = {"url": url_field, **data} # Add URL field at the top return data + + +class RequiredFieldsMixin: + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + for field in self.fields.values(): + field.required = True diff --git a/gmn/serializers.py b/gmn/serializers.py index 9caf3f8..69821aa 100644 --- a/gmn/serializers.py +++ b/gmn/serializers.py @@ -1,17 +1,19 @@ from rest_framework import serializers -from api.mixins import UrlFieldMixin +from api.mixins import RequiredFieldsMixin, UrlFieldMixin from . import models as gmn_models -class GMNSerializer(UrlFieldMixin, serializers.ModelSerializer): +class GMNSerializer(UrlFieldMixin, RequiredFieldsMixin, serializers.ModelSerializer): class Meta: model = gmn_models.GMN fields = "__all__" -class MeasuringpointSerializer(UrlFieldMixin, serializers.ModelSerializer): +class MeasuringpointSerializer( + UrlFieldMixin, RequiredFieldsMixin, serializers.ModelSerializer +): class Meta: model = gmn_models.Measuringpoint fields = "__all__" diff --git a/gmw/serializers.py b/gmw/serializers.py index 1e90ce7..a8004ac 100644 --- a/gmw/serializers.py +++ b/gmw/serializers.py @@ -1,17 +1,24 @@ from rest_framework import serializers -from api.mixins import UrlFieldMixin +from api.mixins import RequiredFieldsMixin, UrlFieldMixin from . import models as gmw_models -class GMWSerializer(UrlFieldMixin, serializers.ModelSerializer): +class GMWSerializer(UrlFieldMixin, RequiredFieldsMixin, serializers.ModelSerializer): class Meta: model = gmw_models.GMW fields = "__all__" -class MonitoringTubeSerializer(UrlFieldMixin, serializers.ModelSerializer): +class MonitoringTubeSerializer( + UrlFieldMixin, RequiredFieldsMixin, serializers.ModelSerializer +): class Meta: model = gmw_models.MonitoringTube fields = "__all__" + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + for field in self.fields.values(): + field.required = True