mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-05 04:50:12 +03:00
Fix #3844, refine validator for fields with <source=> kwargs
This commit is contained in:
parent
e7fbd264ca
commit
a5cead5060
|
@ -35,7 +35,7 @@ class UniqueValidator(object):
|
||||||
"""
|
"""
|
||||||
# Determine the underlying model field name. This may not be the
|
# Determine the underlying model field name. This may not be the
|
||||||
# same as the serializer field name if `source=<>` is set.
|
# 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.
|
# Determine the existing instance, if this is an update operation.
|
||||||
self.instance = getattr(serializer_field.parent, 'instance', None)
|
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
|
# Determine the underlying model field names. These may not be the
|
||||||
# same as the serializer field names if `source=<>` is set.
|
# same as the serializer field names if `source=<>` is set.
|
||||||
self.field_name = serializer.fields[self.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[0]
|
self.date_field_name = serializer.fields[self.date_field].source_attrs[-1]
|
||||||
# Determine the existing instance, if this is an update operation.
|
# Determine the existing instance, if this is an update operation.
|
||||||
self.instance = getattr(serializer, 'instance', None)
|
self.instance = getattr(serializer, 'instance', None)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user