本文整理汇总了Python中marshmallow.fields.Date方法的典型用法代码示例。如果您正苦于以下问题:Python fields.Date方法的具体用法?Python fields.Date怎么用?Python fields.Date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类marshmallow.fields
的用法示例。
在下文中一共展示了fields.Date方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_datetime_based
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Date [as 别名]
def test_datetime_based():
class TestSchema(Schema):
f_date = fields.Date()
f_datetime = fields.DateTime()
f_time = fields.Time()
schema = TestSchema()
dumped = validate_and_dump(schema)
assert dumped["definitions"]["TestSchema"]["properties"]["f_date"] == {
"format": "date",
"title": "f_date",
"type": "string",
}
assert dumped["definitions"]["TestSchema"]["properties"]["f_datetime"] == {
"format": "date-time",
"title": "f_datetime",
"type": "string",
}
assert dumped["definitions"]["TestSchema"]["properties"]["f_time"] == {
"format": "time",
"title": "f_time",
"type": "string",
}
示例2: get_date
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Date [as 别名]
def get_date(key, value, is_list=False, is_optional=False, default=None, options=None):
"""
Get the value corresponding to the key and converts it to `date`/`list(date)`.
Args:
key: the dict key.
value: the value to parse.
is_list: If this is one element or a list of elements.
is_optional: To raise an error if key was not found.
default: default value if is_optional is True.
options: list/tuple if provided, the value must be one of these values.
Returns:
`date`: value corresponding to the key.
"""
if is_list:
return _get_typed_list_value(
key=key,
value=value,
target_type=date,
type_convert=fields.Date().deserialize,
is_optional=is_optional,
default=default,
options=options,
)
return _get_typed_value(
key=key,
value=value,
target_type=date,
type_convert=fields.Date().deserialize,
is_optional=is_optional,
default=default,
options=options,
)