From eabaae81acf9608e86d3802c8c74bc9c5e5205d7 Mon Sep 17 00:00:00 2001 From: Bai Date: Thu, 5 Nov 2020 13:11:16 +0800 Subject: [PATCH] =?UTF-8?q?perf(application):=20=E4=BC=98=E5=8C=96RemoteAp?= =?UTF-8?q?p=E5=BA=94=E7=94=A8Chrome=E5=BA=8F=E5=88=97=E7=B1=BB=E7=9A=84?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E4=B8=BB=E9=94=AE=E5=85=B3=E8=81=94?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/applications/serializers/remote_app.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/apps/applications/serializers/remote_app.py b/apps/applications/serializers/remote_app.py index 90f32f8cd..65190f38c 100644 --- a/apps/applications/serializers/remote_app.py +++ b/apps/applications/serializers/remote_app.py @@ -21,17 +21,11 @@ logger = get_logger(__file__) class CharPrimaryKeyRelatedField(serializers.PrimaryKeyRelatedField): def to_internal_value(self, data): - if self.pk_field is not None: - data = self.pk_field.to_internal_value(data) - try: - instance = self.get_queryset().get(pk=data) - return str(instance.id) - except ObjectDoesNotExist: - self.fail('does_not_exist', pk_value=data) - except (TypeError, ValueError): - self.fail('incorrect_type', data_type=type(data).__name__) + instance = super().to_internal_value(data) + return str(instance.id) def to_representation(self, value): + # value is instance.id if self.pk_field is not None: return self.pk_field.to_representation(value) return value