本文整理匯總了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,
)