mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-02 20:54:42 +03:00
partial argument should override required
This commit is contained in:
parent
3b43d41e91
commit
1adfc41dc7
|
@ -53,6 +53,8 @@ class Field(object):
|
|||
self.parent = parent
|
||||
self.root = parent.root or parent
|
||||
self.context = self.root.context
|
||||
if self.root.partial:
|
||||
self.required = False
|
||||
|
||||
def field_from_native(self, data, files, field_name, into):
|
||||
"""
|
||||
|
@ -148,7 +150,7 @@ class WritableField(Field):
|
|||
self.widget = widget
|
||||
|
||||
def validate(self, value):
|
||||
if value in validators.EMPTY_VALUES and self.required and not self.root.partial:
|
||||
if value in validators.EMPTY_VALUES and self.required:
|
||||
raise ValidationError(self.error_messages['required'])
|
||||
|
||||
def run_validators(self, value):
|
||||
|
@ -186,7 +188,7 @@ class WritableField(Field):
|
|||
if self.default is not None:
|
||||
native = self.default
|
||||
else:
|
||||
if self.required and not self.root.partial:
|
||||
if self.required:
|
||||
raise ValidationError(self.error_messages['required'])
|
||||
return
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user