Do not require UniqueTogether validation for updates (PATCH) since the update may be partial.

This commit is contained in:
Jarrod Baumann 2014-11-05 00:22:49 -06:00
parent 5ee472718a
commit 4b62a8e8bd

View File

@ -592,6 +592,7 @@ class ModelSerializer(Serializer):
# Note that we make sure to check `unique_together` both on the # Note that we make sure to check `unique_together` both on the
# base model class, but also on any parent classes. # base model class, but also on any parent classes.
for parent_class in [model_class] + list(model_class._meta.parents.keys()): for parent_class in [model_class] + list(model_class._meta.parents.keys()):
if self.context.get('request').method != 'PATCH':
for unique_together in parent_class._meta.unique_together: for unique_together in parent_class._meta.unique_together:
if field_names.issuperset(set(unique_together)): if field_names.issuperset(set(unique_together)):
validator = UniqueTogetherValidator( validator = UniqueTogetherValidator(