refactor(serializer): 设置 `BulkSerializerMixin` 的默认 `ListSerializer` 为 `AdaptedBulkListSerializer`

pull/4429/head
xinwen 4 years ago committed by 老广
parent 1b052a8729
commit e98235ca27

@ -8,7 +8,6 @@ from rest_framework.utils import html
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
from rest_framework.exceptions import ValidationError from rest_framework.exceptions import ValidationError
from rest_framework.fields import SkipField, empty from rest_framework.fields import SkipField, empty
__all__ = ['BulkSerializerMixin', 'BulkListSerializerMixin', 'CommonSerializerMixin', 'CommonBulkSerializerMixin'] __all__ = ['BulkSerializerMixin', 'BulkListSerializerMixin', 'CommonSerializerMixin', 'CommonBulkSerializerMixin']
@ -50,6 +49,15 @@ class BulkSerializerMixin(object):
self.initial_data = data self.initial_data = data
return super().run_validation(data) return super().run_validation(data)
@classmethod
def many_init(cls, *args, **kwargs):
meta = getattr(cls, 'Meta', None)
assert meta is not None, 'Must have `Meta`'
if not hasattr(meta, 'list_serializer_class'):
from common.drf.serializers import AdaptedBulkListSerializer
meta.list_serializer_class = AdaptedBulkListSerializer
return super(BulkSerializerMixin, cls).many_init(*args, **kwargs)
class BulkListSerializerMixin(object): class BulkListSerializerMixin(object):
""" """

@ -12,7 +12,6 @@ class TerminalSerializer(BulkModelSerializer):
class Meta: class Meta:
model = Terminal model = Terminal
list_serializer_class = AdaptedBulkListSerializer
fields = [ fields = [
'id', 'name', 'remote_addr', 'http_port', 'ssh_port', 'id', 'name', 'remote_addr', 'http_port', 'ssh_port',
'comment', 'is_accepted', "is_active", 'session_online', 'comment', 'is_accepted', "is_active", 'session_online',

Loading…
Cancel
Save