diff options
| author | Carlton Gibson | 2014-12-01 11:22:39 +0100 |
|---|---|---|
| committer | Carlton Gibson | 2014-12-01 11:22:39 +0100 |
| commit | ef26f43de4a0c9ac3081c06a383b5d3d4d007797 (patch) | |
| tree | bf6abcd15f0e58f4fa79a83cd4e051b8987dd311 /rest_framework/validators.py | |
| parent | c50a42bddc66e28d624cd3caadd2d63502ac2e6e (diff) | |
| parent | 72c4ec4e189796e506655e275cd9c77abe98e1b9 (diff) | |
| download | django-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.py | 14 |
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) |
