似乎我只能在PyEve中指定全局DATE_FORMAT。如何为同一资源中的不同字段指定不同的格式?
您可以创建自定义数据类型来处理新格式。这是来自文档(https://docs.python-eve.org/en/stable/validation.html#custom-data-types)的示例:
def _validate_type_objectid(self, value):
""" Enables validation for `objectid` schema attribute.
:param value: field value.
"""
if isinstance(value, ObjectId):
return True
然后在架构中使用自定义类型:
'schema': {
'owner': {
'type': 'objectid',
'required': True,
},
}