aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/serializers.py
diff options
context:
space:
mode:
authorTom Christie2014-11-05 15:23:13 +0000
committerTom Christie2014-11-05 15:23:13 +0000
commit49fae230005bba4607f425d90de77363d6b8659e (patch)
tree5152a29e89980bb58cb45059df4f54e12a6df412 /rest_framework/serializers.py
parentd048d32876e4a2f4acb6848b809097b9b9d48e50 (diff)
downloaddjango-rest-framework-49fae230005bba4607f425d90de77363d6b8659e.tar.bz2
Pass through kwargs to both Serializer and ListSerializer
Diffstat (limited to 'rest_framework/serializers.py')
-rw-r--r--rest_framework/serializers.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py
index 9e5d0cab..dfac75fc 100644
--- a/rest_framework/serializers.py
+++ b/rest_framework/serializers.py
@@ -43,6 +43,12 @@ import warnings
from rest_framework.relations import * # NOQA
from rest_framework.fields import * # NOQA
+LIST_SERIALIZER_KWARGS = (
+ 'read_only', 'write_only', 'required', 'default', 'initial', 'source',
+ 'label', 'help_text', 'style', 'error_messages',
+ 'instance', 'data', 'partial', 'context'
+)
+
# BaseSerializer
# --------------
@@ -52,7 +58,6 @@ class BaseSerializer(Field):
The BaseSerializer class provides a minimal class which may be used
for writing custom serializer implementations.
"""
-
def __init__(self, instance=None, data=None, **kwargs):
self.instance = instance
self._initial_data = data
@@ -65,8 +70,11 @@ class BaseSerializer(Field):
# We override this method in order to automagically create
# `ListSerializer` classes instead when `many=True` is set.
if kwargs.pop('many', False):
- kwargs['child'] = cls()
- return ListSerializer(*args, **kwargs)
+ list_kwargs = {'child': cls(*args, **kwargs)}
+ for key in kwargs.keys():
+ if key in LIST_SERIALIZER_KWARGS:
+ list_kwargs[key] = kwargs[key]
+ return ListSerializer(*args, **list_kwargs)
return super(BaseSerializer, cls).__new__(cls, *args, **kwargs)
def to_internal_value(self, data):