OpenQuizz
Une application de gestion des contenus pédagogiques
Nested Class Reference
Inheritance diagram for Nested:
Collaboration diagram for Nested:

Public Member Functions

def __init__ (self, typing.Union[SchemaABC, type, str, typing.Callable[[], SchemaABC]] nested, *typing.Any default=missing_, typing.Optional[types.StrSequenceOrSet] only=None, types.StrSequenceOrSet exclude=(), bool many=False, typing.Optional[str] unknown=None, **kwargs)
 
def schema (self)
 
- Public Member Functions inherited from Field
None __init__ (self, *typing.Any default=missing_, typing.Any missing=missing_, typing.Optional[str] data_key=None, typing.Optional[str] attribute=None, typing.Optional[typing.Union[typing.Callable[[typing.Any], typing.Any], typing.Iterable[typing.Callable[[typing.Any], typing.Any]],]] validate=None, bool required=False, typing.Optional[bool] allow_none=None, bool load_only=False, bool dump_only=False, typing.Optional[typing.Dict[str, str]] error_messages=None, typing.Optional[typing.Mapping[str, typing.Any]] metadata=None, **additional_metadata)
 
str __repr__ (self)
 
def __deepcopy__ (self, memo)
 
def get_value (self, obj, attr, accessor=None, default=missing_)
 
ValidationError make_error (self, str key, **kwargs)
 
def fail (self, str key, **kwargs)
 
def serialize (self, str attr, typing.Any obj, typing.Optional[typing.Callable[[typing.Any, str, typing.Any], typing.Any]] accessor=None, **kwargs)
 
def deserialize (self, typing.Any value, typing.Optional[str] attr=None, typing.Optional[typing.Mapping[str, typing.Any]] data=None, **kwargs)
 
def context (self)
 
- Public Member Functions inherited from FieldABC
def serialize (self, attr, obj, accessor=None)
 
def deserialize (self, value)
 

Data Fields

 nested
 
 only
 
 exclude
 
 many
 
 unknown
 
- Data Fields inherited from Field
 default
 
 attribute
 
 data_key
 
 validate
 
 validators
 
 allow_none
 
 load_only
 
 dump_only
 
 required
 
 missing
 
 metadata
 
 error_messages
 
 parent
 
 name
 
 root
 

Static Public Attributes

 default_error_messages
 
- Static Public Attributes inherited from Field
 default_error_messages
 
- Static Public Attributes inherited from FieldABC
 parent
 
 name
 
 root
 

Detailed Description

Allows you to nest a :class:`Schema <marshmallow.Schema>`
inside a field.

Examples: ::

    class ChildSchema(Schema):
        id = fields.Str()
        name = fields.Str()
        # Use lambda functions when you need two-way nesting or self-nesting
        parent = fields.Nested(lambda: ParentSchema(only=("id",)), dump_only=True)
        siblings = fields.List(fields.Nested(lambda: ChildSchema(only=("id", "name"))))

    class ParentSchema(Schema):
        id = fields.Str()
        children = fields.List(
            fields.Nested(ChildSchema(only=("id", "parent", "siblings")))
        )
        spouse = fields.Nested(lambda: ParentSchema(only=("id",)))

When passing a `Schema <marshmallow.Schema>` instance as the first argument,
the instance's ``exclude``, ``only``, and ``many`` attributes will be respected.

Therefore, when passing the ``exclude``, ``only``, or ``many`` arguments to `fields.Nested`,
you should pass a `Schema <marshmallow.Schema>` class (not an instance) as the first argument.

::

    # Yes
    author = fields.Nested(UserSchema, only=('id', 'name'))

    # No
    author = fields.Nested(UserSchema(), only=('id', 'name'))

:param nested: `Schema` instance, class, class name (string), or callable that returns a `Schema` instance.
:param exclude: A list or tuple of fields to exclude.
:param only: A list or tuple of fields to marshal. If `None`, all fields are marshalled.
    This parameter takes precedence over ``exclude``.
:param many: Whether the field is a collection of objects.
:param unknown: Whether to exclude, include, or raise an error for unknown
    fields in the data. Use `EXCLUDE`, `INCLUDE` or `RAISE`.
:param kwargs: The same keyword arguments that :class:`Field` receives.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
typing.Union[SchemaABC, type, str, typing.Callable[[], SchemaABC]]  nested,
*typing.Any   default = missing_,
typing.Optional[types.StrSequenceOrSet]   only = None,
types.StrSequenceOrSet   exclude = (),
bool   many = False,
typing.Optional[str]   unknown = None,
**  kwargs 
)

Member Function Documentation

◆ schema()

def schema (   self)
The nested Schema object.

.. versionchanged:: 1.0.0
    Renamed from `serializer` to `schema`.

Field Documentation

◆ default_error_messages

default_error_messages
static

◆ exclude

exclude

◆ many

many

◆ nested

nested

◆ only

only

◆ unknown

unknown

The documentation for this class was generated from the following file: