aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/validators.py
diff options
context:
space:
mode:
authorCarlton Gibson2014-12-01 11:22:39 +0100
committerCarlton Gibson2014-12-01 11:22:39 +0100
commitef26f43de4a0c9ac3081c06a383b5d3d4d007797 (patch)
treebf6abcd15f0e58f4fa79a83cd4e051b8987dd311 /rest_framework/validators.py
parentc50a42bddc66e28d624cd3caadd2d63502ac2e6e (diff)
parent72c4ec4e189796e506655e275cd9c77abe98e1b9 (diff)
downloaddjango-rest-framework-ef26f43de4a0c9ac3081c06a383b5d3d4d007797.tar.bz2
Merge branch 'master' of github.com:tomchristie/django-rest-framework
Diffstat (limited to 'rest_framework/validators.py')
-rw-r--r--rest_framework/validators.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/rest_framework/validators.py b/rest_framework/validators.py
index fa4f1847..7ca4e6a9 100644
--- a/rest_framework/validators.py
+++ b/rest_framework/validators.py
@@ -93,6 +93,9 @@ class UniqueTogetherValidator:
The `UniqueTogetherValidator` always forces an implied 'required'
state on the fields it applies to.
"""
+ if self.instance is not None:
+ return
+
missing = dict([
(field_name, self.missing_message)
for field_name in self.fields
@@ -105,8 +108,17 @@ class UniqueTogetherValidator:
"""
Filter the queryset to all instances matching the given attributes.
"""
+ # If this is an update, then any unprovided field should
+ # have it's value set based on the existing instance attribute.
+ if self.instance is not None:
+ for field_name in self.fields:
+ if field_name not in attrs:
+ attrs[field_name] = getattr(self.instance, field_name)
+
+ # Determine the filter keyword arguments and filter the queryset.
filter_kwargs = dict([
- (field_name, attrs[field_name]) for field_name in self.fields
+ (field_name, attrs[field_name])
+ for field_name in self.fields
])
return queryset.filter(**filter_kwargs)