mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-05 13:00:12 +03:00
Merge ce6c27b228
into fd72a814f8
This commit is contained in:
commit
ec8f5961ef
|
@ -305,15 +305,41 @@ class Field(object):
|
||||||
}
|
}
|
||||||
default_validators = []
|
default_validators = []
|
||||||
default_empty_html = empty
|
default_empty_html = empty
|
||||||
initial = None
|
|
||||||
|
|
||||||
def __init__(self, read_only=False, write_only=False,
|
# allows subclasses to change defaults
|
||||||
required=None, default=empty, initial=empty, source=None,
|
read_only = False
|
||||||
label=None, help_text=None, style=None,
|
write_only = False
|
||||||
error_messages=None, validators=None, allow_null=False):
|
required = None
|
||||||
|
default = empty
|
||||||
|
initial = None
|
||||||
|
source = None
|
||||||
|
label = None
|
||||||
|
help_text = None
|
||||||
|
style = None
|
||||||
|
error_messages = None
|
||||||
|
validators = None
|
||||||
|
allow_null = False
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
self._creation_counter = Field._creation_counter
|
self._creation_counter = Field._creation_counter
|
||||||
Field._creation_counter += 1
|
Field._creation_counter += 1
|
||||||
|
|
||||||
|
# precedence is given to kwargs over class attributes.
|
||||||
|
# you can create a subclass of a Field for maximum reuse while still
|
||||||
|
# needing a one-off instance where you need to change an attribute.
|
||||||
|
read_only = kwargs.pop('read_only', self.read_only)
|
||||||
|
write_only = kwargs.pop('write_only', self.write_only)
|
||||||
|
required = kwargs.pop('required', self.required)
|
||||||
|
default = kwargs.pop('default', self.default)
|
||||||
|
initial = kwargs.pop('initial', self.initial)
|
||||||
|
source = kwargs.pop('source', self.source)
|
||||||
|
label = kwargs.pop('label', self.label)
|
||||||
|
help_text = kwargs.pop('help_text', self.help_text)
|
||||||
|
style = kwargs.pop('style', self.style)
|
||||||
|
error_messages = kwargs.pop('error_messages', self.error_messages)
|
||||||
|
validators = kwargs.pop('validators', self.validators)
|
||||||
|
allow_null = kwargs.pop('allow_null', self.allow_null)
|
||||||
|
|
||||||
# If `required` is unset, then use `True` unless a default is provided.
|
# If `required` is unset, then use `True` unless a default is provided.
|
||||||
if required is None:
|
if required is None:
|
||||||
required = default is empty and not read_only
|
required = default is empty and not read_only
|
||||||
|
@ -329,7 +355,7 @@ class Field(object):
|
||||||
self.required = required
|
self.required = required
|
||||||
self.default = default
|
self.default = default
|
||||||
self.source = source
|
self.source = source
|
||||||
self.initial = self.initial if (initial is empty) else initial
|
self.initial = initial
|
||||||
self.label = label
|
self.label = label
|
||||||
self.help_text = help_text
|
self.help_text = help_text
|
||||||
self.style = {} if style is None else style
|
self.style = {} if style is None else style
|
||||||
|
|
Loading…
Reference in New Issue
Block a user