          self.assertEqual(
              AnotherUniquenessModel._meta.get_field('code').validators, [])
  
  
  # Tests for `UniqueTogetherValidator`
  # -----------------------------------
  
 
</s> remove         self.field_name = serializer_field.source_attrs[0]
 </s> add         self.field_name = serializer_field.source_attrs[-1] </s> remove         self.field_name = serializer.fields[self.field].source_attrs[0]
        self.date_field_name = serializer.fields[self.date_field].source_attrs[0]
 </s> add         self.field_name = serializer.fields[self.field].source_attrs[-1]
        self.date_field_name = serializer.fields[self.date_field].source_attrs[-1]
    def test_related_model_is_unique(self):
        data = {'username': 'existing', 'email': 'new-email@example.com'}
        rs = RelatedModelSerializer(data=data)
        self.assertFalse(rs.is_valid())
        self.assertEqual(rs.errors,
                         {'username': ['This field must be unique.']})
        data = {'username': 'new-username', 'email': 'new-email@example.com'}
        rs = RelatedModelSerializer(data=data)
        self.assertTrue(rs.is_valid())

          self.assertEqual(
              AnotherUniquenessModel._meta.get_field('code').validators, [])
  
    def test_related_model_is_unique(self):
        data = {'username': 'existing', 'email': 'new-email@example.com'}
        rs = RelatedModelSerializer(data=data)
        self.assertFalse(rs.is_valid())
        self.assertEqual(rs.errors,
                         {'username': ['This field must be unique.']})
        data = {'username': 'new-username', 'email': 'new-email@example.com'}
        rs = RelatedModelSerializer(data=data)
        self.assertTrue(rs.is_valid())

  
  # Tests for `UniqueTogetherValidator`
  # -----------------------------------
  
keep keep add keep keep keep keep
 Fix #3844, refine validator for fields with <source=> kwargs

When serializers has fields with something like `source=user.email`, the
uniqueness validator should check `email` field instead of `user`, cause
`user` is a model object. 
tests/test_validators.py