From 2f25e2b24cb29e44d7010449c11e454a776a8df8 Mon Sep 17 00:00:00 2001 From: jiangweidong Date: Sat, 9 Oct 2021 17:49:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=B3=BB=E7=BB=9F=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E8=AE=A4=E8=AF=81=E6=96=B9=E5=BC=8F=E4=BB=8E=E6=89=98=E7=AE=A1?= =?UTF-8?q?=E5=AF=86=E7=A0=81=E6=9B=B4=E6=96=B0=E5=88=B0=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=A8=A1=E5=BC=8F=E5=90=8E=EF=BC=8C=E4=B8=8D?= =?UTF-8?q?=E5=A1=AB=E5=86=99=E7=94=A8=E6=88=B7=E5=90=8D=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/common/mixins/serializers.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/common/mixins/serializers.py b/apps/common/mixins/serializers.py index 88e579369..e9a1641c4 100644 --- a/apps/common/mixins/serializers.py +++ b/apps/common/mixins/serializers.py @@ -297,10 +297,10 @@ class CommonSerializerMixin(DynamicFieldsMixin, DefaultValueFieldsMixin): initial_data: dict def get_initial_value(self, attr, default=None): - if self.instance: - return getattr(self.instance, attr, default) - else: - return self.initial_data.get(attr) + value = self.initial_data.get(attr) + if not value and self.instance: + value = getattr(self.instance, attr, default) + return value class CommonBulkSerializerMixin(BulkSerializerMixin, CommonSerializerMixin):