mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 00:49:49 +03:00
Add dynamic fetching of fields to validate
This commit is contained in:
parent
56ff382b17
commit
cb67a15321
|
@ -361,6 +361,12 @@ class Serializer(BaseSerializer, metaclass=SerializerMetaclass):
|
|||
if not field.write_only:
|
||||
yield field
|
||||
|
||||
def get_fields_to_validate(self, data):
|
||||
"""
|
||||
Override this method if you want more control over the fields you want to validate
|
||||
"""
|
||||
return self._writable_fields
|
||||
|
||||
def get_fields(self):
|
||||
"""
|
||||
Returns a dictionary of {field_name: field_instance}.
|
||||
|
@ -466,7 +472,7 @@ class Serializer(BaseSerializer, metaclass=SerializerMetaclass):
|
|||
|
||||
ret = OrderedDict()
|
||||
errors = OrderedDict()
|
||||
fields = self._writable_fields
|
||||
fields = self.get_fields_to_validate(data)
|
||||
|
||||
for field in fields:
|
||||
validate_method = getattr(self, 'validate_' + field.field_name, None)
|
||||
|
|
Loading…
Reference in New Issue
Block a user