mirror of https://github.com/jumpserver/jumpserver
perf(application): 优化RemoteApp应用Chrome序列类的字符串主键关联字段
parent
6df331cbed
commit
eabaae81ac
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue