diff --git a/rest_framework/validators.py b/rest_framework/validators.py index a21f67e60..83ad6f7d8 100644 --- a/rest_framework/validators.py +++ b/rest_framework/validators.py @@ -35,7 +35,7 @@ class UniqueValidator(object): """ # Determine the underlying model field name. This may not be the # same as the serializer field name if `source=<>` is set. - self.field_name = serializer_field.source_attrs[0] + self.field_name = serializer_field.source_attrs[-1] # Determine the existing instance, if this is an update operation. self.instance = getattr(serializer_field.parent, 'instance', None) @@ -174,8 +174,8 @@ class BaseUniqueForValidator(object): """ # Determine the underlying model field names. These may not be the # same as the serializer field names if `source=<>` is set. - self.field_name = serializer.fields[self.field].source_attrs[0] - self.date_field_name = serializer.fields[self.date_field].source_attrs[0] + self.field_name = serializer.fields[self.field].source_attrs[-1] + self.date_field_name = serializer.fields[self.date_field].source_attrs[-1] # Determine the existing instance, if this is an update operation. self.instance = getattr(serializer, 'instance', None)