|
76 | 76 | 'instance', 'data', 'partial', 'context', 'allow_null',
|
77 | 77 | 'max_length', 'min_length'
|
78 | 78 | )
|
| 79 | +LIST_SERIALIZER_KWARGS_REMOVE = ('allow_empty', 'min_length', 'max_length') |
79 | 80 |
|
80 | 81 | ALL_FIELDS = '__all__'
|
81 | 82 |
|
@@ -145,19 +146,12 @@ def many_init(cls, *args, **kwargs):
|
145 | 146 | kwargs['child'] = cls()
|
146 | 147 | return CustomListSerializer(*args, **kwargs)
|
147 | 148 | """
|
148 |
| - allow_empty = kwargs.pop('allow_empty', None) |
149 |
| - max_length = kwargs.pop('max_length', None) |
150 |
| - min_length = kwargs.pop('min_length', None) |
151 |
| - child_serializer = cls(*args, **kwargs) |
152 |
| - list_kwargs = { |
153 |
| - 'child': child_serializer, |
154 |
| - } |
155 |
| - if allow_empty is not None: |
156 |
| - list_kwargs['allow_empty'] = allow_empty |
157 |
| - if max_length is not None: |
158 |
| - list_kwargs['max_length'] = max_length |
159 |
| - if min_length is not None: |
160 |
| - list_kwargs['min_length'] = min_length |
| 149 | + list_kwargs = {} |
| 150 | + for key in LIST_SERIALIZER_KWARGS_REMOVE: |
| 151 | + value = kwargs.pop(key, None) |
| 152 | + if value is not None: |
| 153 | + list_kwargs[key] = value |
| 154 | + list_kwargs['child'] = cls(*args, **kwargs) |
161 | 155 | list_kwargs.update({
|
162 | 156 | key: value for key, value in kwargs.items()
|
163 | 157 | if key in LIST_SERIALIZER_KWARGS
|
|
0 commit comments