jumpserver/apps/common/drf/fields.py

26 lines
479 B
Python
Raw Normal View History

# -*- coding: utf-8 -*-
#
2020-07-20 02:42:22 +00:00
from rest_framework import serializers
2020-07-20 02:42:22 +00:00
__all__ = [
'ReadableHiddenField',
]
# ReadableHiddenField
# -------------------
class ReadableHiddenField(serializers.HiddenField):
""" 可读的 HiddenField """
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.write_only = False
def to_representation(self, value):
if hasattr(value, 'id'):
return getattr(value, 'id')
return value