aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/relations.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/relations.py
parentd048d32876e4a2f4acb6848b809097b9b9d48e50 (diff)
downloaddjango-rest-framework-49fae230005bba4607f425d90de77363d6b8659e.tar.bz2
Pass through kwargs to both Serializer and ListSerializer
Diffstat (limited to 'rest_framework/relations.py')
-rw-r--r--rest_framework/relations.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/rest_framework/relations.py b/rest_framework/relations.py
index 1665dd35..f6ae30d0 100644
--- a/rest_framework/relations.py
+++ b/rest_framework/relations.py
@@ -13,6 +13,11 @@ class PKOnlyObject(object):
def __init__(self, pk):
self.pk = pk
+MANY_RELATION_KWARGS = (
+ 'read_only', 'write_only', 'required', 'default', 'initial', 'source',
+ 'label', 'help_text', 'style', 'error_messages'
+)
+
class RelatedField(Field):
def __init__(self, **kwargs):
@@ -31,10 +36,11 @@ class RelatedField(Field):
# We override this method in order to automagically create
# `ManyRelation` classes instead when `many=True` is set.
if kwargs.pop('many', False):
- return ManyRelation(
- child_relation=cls(*args, **kwargs),
- read_only=kwargs.get('read_only', False)
- )
+ list_kwargs = {'child_relation': cls(*args, **kwargs)}
+ for key in kwargs.keys():
+ if key in MANY_RELATION_KWARGS:
+ list_kwargs[key] = kwargs[key]
+ return ManyRelation(**list_kwargs)
return super(RelatedField, cls).__new__(cls, *args, **kwargs)
def run_validation(self, data=empty):