From 85cfb8f6802fc97713e4e2e0c712769dc3afb473 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 8 May 2026 13:45:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20LabelTemplate=20=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E5=8C=96=E5=99=A8=E5=85=81=E8=AE=B8=20coder=5Fip=20=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E5=AD=97=E7=AC=A6=E4=B8=B2/null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Why: DRF IPAddressField 默认拒绝空串, 前端清空 IP 保存时报 400 Co-Authored-By: Claude Opus 4.7 (1M context) --- apps/cm/serializers.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/cm/serializers.py b/apps/cm/serializers.py index 456e3886..fe431539 100644 --- a/apps/cm/serializers.py +++ b/apps/cm/serializers.py @@ -43,6 +43,11 @@ class LabelMatSerializer(serializers.ModelSerializer): class LabelTemplateSerializer(CustomModelSerializer): + coder_ip = serializers.IPAddressField(required=False, allow_null=True, allow_blank=True) + class Meta: model = LabelTemplate - fields = '__all__' \ No newline at end of file + fields = '__all__' + + def validate_coder_ip(self, value): + return value or None \ No newline at end of file