Mapping Helpers¶
Odin includes a few helpers to help defining mappings.
Defining Mappings¶
When defining mappings using the shorthand mappings property these methods simplify the definition of mapping rules. They also provide sensible defaults.
-
odin.mapping.
define
(from_field=None, action=None, to_field=None, to_list=False, bind=False, skip_if_none=False)[source]¶ Helper method for defining a mapping.
Parameters: - from_field – Source field to map from.
- action – Action callable to perform during mapping, accepted fields differ based on options.
- to_field – Destination field to map to; if not specified the from_field
- to_list – Assume the result is a list (rather than a multi value tuple).
- bind – During the mapping operation the first parameter should be the mapping instance.
- skip_if_none – If the from field is
None
do not include the field (this allows the destination object to define it’s own defaults etc)
Returns: A mapping definition.
-
odin.mapping.
assign
(to_field, action, to_list=False, bind=True, skip_if_none=False)[source]¶ Helper method for defining an assignment mapping.
Parameters: - to_field – Destination field to map to; if not specified the from_field
- action – Action callable to perform during mapping, accepted fields differ based on options.
- to_list – Assume the result is a list (rather than a multi value tuple).
- bind – During the mapping operation the first parameter should be the mapping instance; defaults to True
- skip_if_none – If the from field is
None
do not include the field (this allows the destination object to define it’s own defaults etc)
Returns: A mapping definition.