MCPcopy Index your code
hub / github.com/encode/django-rest-framework / __init__

Method __init__

rest_framework/fields.py:299–343  ·  view source on GitHub ↗
(self, *, read_only=False, write_only=False,
                 required=None, default=empty, initial=empty, source=None,
                 label=None, help_text=None, style=None,
                 error_messages=None, validators=None, allow_null=False)

Source from the content-addressed store, hash-verified

297 initial = None
298
299 def __init__(self, *, read_only=False, write_only=False,
300 required=None, default=empty, initial=empty, source=None,
301 label=None, help_text=None, style=None,
302 error_messages=None, validators=None, allow_null=False):
303 self._creation_counter = Field._creation_counter
304 Field._creation_counter += 1
305
306 # If `required` is unset, then use `True` unless a default is provided.
307 if required is None:
308 required = default is empty and not read_only
309
310 # Some combinations of keyword arguments do not make sense.
311 assert not (read_only and write_only), NOT_READ_ONLY_WRITE_ONLY
312 assert not (read_only and required), NOT_READ_ONLY_REQUIRED
313 assert not (required and default is not empty), NOT_REQUIRED_DEFAULT
314 assert not (read_only and self.__class__ == Field), USE_READONLYFIELD
315
316 self.read_only = read_only
317 self.write_only = write_only
318 self.required = required
319 self.default = default
320 self.source = source
321 self.initial = self.initial if (initial is empty) else initial
322 self.label = label
323 self.help_text = help_text
324 self.style = {} if style is None else style
325 self.allow_null = allow_null
326
327 if self.default_empty_html is not empty:
328 if default is not empty:
329 self.default_empty_html = default
330
331 if validators is not None:
332 self.validators = list(validators)
333
334 # These are set up by `.bind()` when the field is added to a serializer.
335 self.field_name = None
336 self.parent = None
337
338 # Collect default error message from self and parent classes
339 messages = {}
340 for cls in reversed(self.__class__.__mro__):
341 messages.update(getattr(cls, 'default_error_messages', {}))
342 messages.update(error_messages or {})
343 self.error_messages = messages
344
345 # Allow generic typing checking for fields.
346 def __class_getitem__(cls, *args, **kwargs):

Callers 15

__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45

Calls 1

updateMethod · 0.45

Tested by

no test coverage detected