fix: 资产 克隆有切换至的账号400 (#10266)

Co-authored-by: feng <1304903146@qq.com>
pull/10268/head
fit2bot 2 years ago committed by GitHub
parent 11ad6ab273
commit dc5f7a5c05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,6 +2,7 @@
# #
import phonenumbers import phonenumbers
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Model
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from rest_framework import serializers from rest_framework import serializers
from rest_framework.fields import ChoiceField, empty from rest_framework.fields import ChoiceField, empty
@ -118,11 +119,15 @@ class ObjectRelatedField(serializers.RelatedField):
return data return data
def to_internal_value(self, data): def to_internal_value(self, data):
queryset = self.get_queryset()
if isinstance(data, Model):
return queryset.get(pk=data.pk)
if not isinstance(data, dict): if not isinstance(data, dict):
pk = data pk = data
else: else:
pk = data.get("id") or data.get("pk") or data.get(self.attrs[0]) pk = data.get("id") or data.get("pk") or data.get(self.attrs[0])
queryset = self.get_queryset()
try: try:
if isinstance(data, bool): if isinstance(data, bool):
raise TypeError raise TypeError

Loading…
Cancel
Save