From 83a00c959266af4fe95025c4c06974714ffd57f4 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Tue, 2 Jul 2024 15:19:08 +0200 Subject: [PATCH] Allow send empty string on not required in custom contribution API --- georiviere/portal/serializers/contribution.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/georiviere/portal/serializers/contribution.py b/georiviere/portal/serializers/contribution.py index a97806d4..1e152c4b 100644 --- a/georiviere/portal/serializers/contribution.py +++ b/georiviere/portal/serializers/contribution.py @@ -239,8 +239,11 @@ def __init__(self, *args, **kwargs): output_field = serializers.DateTimeField required = key in schema.get("required", []) # make field required or not + kwargs = {"label": field.get("title"), "required": required} + if output_field == serializers.CharField: + kwargs["allow_blank"] = not required self.fields[key] = output_field( - label=field.get("title"), required=required, allow_blank=not required + **kwargs ) # station is required if defined at custom_type level. Geom is not required because replace by station geom