API¶
Schemas¶
- class sweetrpg_model_core.schema.base.BaseSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool = False, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]¶
Base type for schema classes. Inherit from this type for database schema objects to gain ID and date conversion pre-load functionality, and to have ID and audit fields setup automatically.
- _abc_impl = <_abc._abc_data object>¶
- _declared_fields: Dict[str, ma_fields.Field] = {'created_at': <fields.DateTime(dump_default=<marshmallow.missing>, attribute=None, validate=None, required=True, load_only=False, dump_only=False, load_default=<marshmallow.missing>, allow_none=False, error_messages={'required': 'Missing data for required field.', 'null': 'Field may not be null.', 'validator_failed': 'Invalid value.', 'invalid': 'Not a valid {obj_type}.', 'invalid_awareness': 'Not a valid {awareness} {obj_type}.', 'format': '"{input}" cannot be formatted as a {obj_type}.'})>, 'created_by': <fields.String(dump_default=<marshmallow.missing>, attribute=None, validate=None, required=True, load_only=False, dump_only=False, load_default=<marshmallow.missing>, allow_none=False, error_messages={'required': 'Missing data for required field.', 'null': 'Field may not be null.', 'validator_failed': 'Invalid value.', 'invalid': 'Not a valid string.', 'invalid_utf8': 'Not a valid utf-8 string.'})>, 'deleted_at': <fields.DateTime(dump_default=<marshmallow.missing>, attribute=None, validate=None, required=False, load_only=False, dump_only=False, load_default=<marshmallow.missing>, allow_none=True, error_messages={'required': 'Missing data for required field.', 'null': 'Field may not be null.', 'validator_failed': 'Invalid value.', 'invalid': 'Not a valid {obj_type}.', 'invalid_awareness': 'Not a valid {awareness} {obj_type}.', 'format': '"{input}" cannot be formatted as a {obj_type}.'})>, 'deleted_by': <fields.String(dump_default=<marshmallow.missing>, attribute=None, validate=None, required=False, load_only=False, dump_only=False, load_default=<marshmallow.missing>, allow_none=True, error_messages={'required': 'Missing data for required field.', 'null': 'Field may not be null.', 'validator_failed': 'Invalid value.', 'invalid': 'Not a valid string.', 'invalid_utf8': 'Not a valid utf-8 string.'})>, 'id': <fields.String(dump_default=<marshmallow.missing>, attribute=None, validate=None, required=False, load_only=False, dump_only=False, load_default=<marshmallow.missing>, allow_none=False, error_messages={'required': 'Missing data for required field.', 'null': 'Field may not be null.', 'validator_failed': 'Invalid value.', 'invalid': 'Not a valid string.', 'invalid_utf8': 'Not a valid utf-8 string.'})>, 'updated_at': <fields.DateTime(dump_default=<marshmallow.missing>, attribute=None, validate=None, required=True, load_only=False, dump_only=False, load_default=<marshmallow.missing>, allow_none=False, error_messages={'required': 'Missing data for required field.', 'null': 'Field may not be null.', 'validator_failed': 'Invalid value.', 'invalid': 'Not a valid {obj_type}.', 'invalid_awareness': 'Not a valid {awareness} {obj_type}.', 'format': '"{input}" cannot be formatted as a {obj_type}.'})>, 'updated_by': <fields.String(dump_default=<marshmallow.missing>, attribute=None, validate=None, required=True, load_only=False, dump_only=False, load_default=<marshmallow.missing>, allow_none=False, error_messages={'required': 'Missing data for required field.', 'null': 'Field may not be null.', 'validator_failed': 'Invalid value.', 'invalid': 'Not a valid string.', 'invalid_utf8': 'Not a valid utf-8 string.'})>}¶
- _hooks: Dict[types.Tag, List[str]] = {('post_load', False): ['make_object'], ('pre_load', False): ['handle_dates', 'handle_id']}¶
- make_object(data, **kwargs)[source]¶
Create a model object from the provided data.
- Parameters:
data – A dictionary of data to populate the model object.
- Returns:
An instance of the model_class.
- opts: SchemaOpts = <marshmallow.schema.SchemaOpts object>¶
Converters¶
- sweetrpg_model_core.convert.date.to_datetime(value, tz=None, attr=None, data=None, **kwargs)[source]¶
Deserializes a database value to a Python datetime. This function can be used as a callback for the Marshmallow
fields.Function
field type.- Parameters:
- Return datetime.datetime:
Python datetime object
- sweetrpg_model_core.convert.date.to_timestamp(value, attr=None, obj=None, **kwargs)[source]¶
Serialize an object value to a MongoDB timestamp. This function can be used as a callback for the Marshmallow
fields.Function
field type.- Parameters:
- Return bson.timestamp.Timestamp:
MongoDB Timestamp object