mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 00:04:16 +03:00
Pass init arguments through to serializer from pagination serializer.
Closes #2355. Normally a serializer won't need these arguments on __init__, but if a user has customized __init__ they may expect them to be available.
This commit is contained in:
parent
6fd33ddea9
commit
26ac2656e5
|
@ -37,16 +37,13 @@ class PreviousPageField(serializers.Field):
|
||||||
return replace_query_param(url, self.page_field, page)
|
return replace_query_param(url, self.page_field, page)
|
||||||
|
|
||||||
|
|
||||||
class DefaultObjectSerializer(serializers.ReadOnlyField):
|
class DefaultObjectSerializer(serializers.Serializer):
|
||||||
"""
|
"""
|
||||||
If no object serializer is specified, then this serializer will be applied
|
If no object serializer is specified, then this serializer will be applied
|
||||||
as the default.
|
as the default.
|
||||||
"""
|
"""
|
||||||
|
def to_representation(self, value):
|
||||||
def __init__(self, source=None, many=None, context=None):
|
return value
|
||||||
# Note: Swallow context and many kwargs - only required for
|
|
||||||
# eg. ModelSerializer.
|
|
||||||
super(DefaultObjectSerializer, self).__init__(source=source)
|
|
||||||
|
|
||||||
|
|
||||||
class BasePaginationSerializer(serializers.Serializer):
|
class BasePaginationSerializer(serializers.Serializer):
|
||||||
|
@ -74,10 +71,9 @@ class BasePaginationSerializer(serializers.Serializer):
|
||||||
list_serializer_class = serializers.ListSerializer
|
list_serializer_class = serializers.ListSerializer
|
||||||
|
|
||||||
self.fields[results_field] = list_serializer_class(
|
self.fields[results_field] = list_serializer_class(
|
||||||
child=object_serializer(),
|
child=object_serializer(*args, **kwargs),
|
||||||
source='object_list'
|
source='object_list'
|
||||||
)
|
)
|
||||||
self.fields[results_field].bind(field_name=results_field, parent=self)
|
|
||||||
|
|
||||||
|
|
||||||
class PaginationSerializer(BasePaginationSerializer):
|
class PaginationSerializer(BasePaginationSerializer):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user