pydent.marshaller.fields.Nested

class pydent.marshaller.fields.Nested(nested, many=None, data_key=None, allow_none=None, lazy=None)[source]

Bases: pydent.marshaller.fields.Field

Represents a field that returns another nested instance.

Nested relationship initializer.

Parameters
  • nested (SchemaModel) – the nested name of nested field. Should exist in the ModelRegistery.

  • many (bool) – whether to treat serializations and deserializations as a per-item basis in a list

  • data_key (basestring) – the data_key, or attribute name, of this field. Calling this as an attribute to the registered nested should return this field’s descriptor.

  • allow_none (bool) – whether to return None if None is received in deserialization or serializaiton methods

  • lazy (Optional[bool]) – if set to True (default), perform lazy serialization and deserialization. If the data received by deserialize is the expected nested, return that data. If the object recieved by serialize is not the expected nested, return that data.

__init__(nested, many=None, data_key=None, allow_none=None, lazy=None)[source]

Nested relationship initializer.

Parameters
  • nested (SchemaModel) – the nested name of nested field. Should exist in the ModelRegistery.

  • many (bool) – whether to treat serializations and deserializations as a per-item basis in a list

  • data_key (basestring) – the data_key, or attribute name, of this field. Calling this as an attribute to the registered nested should return this field’s descriptor.

  • allow_none (bool) – whether to return None if None is received in deserialization or serializaiton methods

  • lazy (Optional[bool]) – if set to True (default), perform lazy serialization and deserialization. If the data received by deserialize is the expected nested, return that data. If the object recieved by serialize is not the expected nested, return that data.

Methods

__init__(nested[, many, data_key, …])

Nested relationship initializer.

deserialize(owner, data)

rtype

Optional[dict]

get_model()

register(name, objtype)

Registers the field to a nested class.

serialize(owner, data)

rtype

Union[dict, None, List]

set_data_key(key)

ACCESSOR

alias of pydent.marshaller.descriptors.MarshallingAccessor

register(name, objtype)

Registers the field to a nested class. Instantiates the corresponding descriptor (i.e. accessor)

Parameters
  • name (str) – name of the field

  • objtype (Type) – the nested class to register the field to

Returns

None

Return type

None