aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/serializers.py
diff options
context:
space:
mode:
authorTom Christie2015-01-21 13:12:14 +0000
committerTom Christie2015-01-21 13:12:14 +0000
commit9ec08ce57889dc329506a572044438a55da61303 (patch)
tree6ef0132e70ae38680a006322a31c272ec2ae4d6b /rest_framework/serializers.py
parent3cc39ffbceffc5fdbb511d9a10e7732329e8baa4 (diff)
parent9d24809a4dee67ee414ee79820331f0794c42a13 (diff)
downloaddjango-rest-framework-9ec08ce57889dc329506a572044438a55da61303.tar.bz2
Merge master
Diffstat (limited to 'rest_framework/serializers.py')
-rw-r--r--rest_framework/serializers.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py
index 77d3f202..b91ecebc 100644
--- a/rest_framework/serializers.py
+++ b/rest_framework/serializers.py
@@ -253,7 +253,7 @@ class SerializerMetaclass(type):
# If this class is subclassing another Serializer, add that Serializer's
# fields. Note that we loop over the bases in *reverse*. This is necessary
# in order to maintain the correct order of fields.
- for base in bases[::-1]:
+ for base in reversed(bases):
if hasattr(base, '_declared_fields'):
fields = list(base._declared_fields.items()) + fields
@@ -899,7 +899,15 @@ class ModelSerializer(Serializer):
if fields is not None:
# Ensure that all declared fields have also been included in the
# `Meta.fields` option.
- for field_name in declared_fields:
+
+ # Do not require any fields that are declared a parent class,
+ # in order to allow serializer subclasses to only include
+ # a subset of fields.
+ required_field_names = set(declared_fields)
+ for cls in self.__class__.__bases__:
+ required_field_names -= set(getattr(cls, '_declared_fields', []))
+
+ for field_name in required_field_names:
assert field_name in fields, (
"The field '{field_name}' was declared on serializer "
"{serializer_class}, but has not been included in the "