Skip to content
Browse files

Added a get_excluded_fieldnames() method.

Model validation now excludes fields not listed in Meta fields (if set).
  • Loading branch information...
1 parent f104f74 commit 899f96ae9186e68009dba5d54246232d34457354 @markotibold markotibold committed
Showing with 12 additions and 1 deletion.
  1. +12 −1 rest_framework/serializers.py
View
13 rest_framework/serializers.py
@@ -119,6 +119,17 @@ def get_default_fields(self):
"""
return {}
+ def get_excluded_fieldnames(self):
+ """
+ Returns the fieldnames that should not be validated.
+ """
+ excluded_fields = list(self.opts.exclude)
+ for field in self.fields.keys() + self.default_fields.keys():
+ if self.opts.fields:
+ if field not in self.opts.fields + self.opts.exclude:
+ excluded_fields.append(field)
+ return excluded_fields
+
def get_fields(self):
"""
Returns the complete set of fields for the object as a dict.
@@ -466,7 +477,7 @@ def validate(self, attrs):
def perform_model_validation(self, restored_object):
# Call Django's full_clean() which in turn calls: Model.clean_fields(), Model.clean(), Model.validat_unique()
- restored_object.full_clean(exclude=list(self.opts.exclude))
+ restored_object.full_clean(exclude=list(self.get_excluded_fieldnames()))
def restore_object(self, attrs, instance=None):
"""

0 comments on commit 899f96a

Please sign in to comment.
Something went wrong with that request. Please try again.