本文整理汇总了Python中amcat.models.Article.static_fields方法的典型用法代码示例。如果您正苦于以下问题:Python Article.static_fields方法的具体用法?Python Article.static_fields怎么用?Python Article.static_fields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类amcat.models.Article
的用法示例。
在下文中一共展示了Article.static_fields方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: from_field_name
# 需要导入模块: from amcat.models import Article [as 别名]
# 或者: from amcat.models.Article import static_fields [as 别名]
def from_field_name(cls, field_name: str, **kwargs):
"""Construct a category object corresponding to the field_name's type. For example,
the field 'date' would map to a IntervalCategory, while author would map to
TextCategory.
@param kwargs: additional parameters passed to corresponding Category"""
is_json_field = field_name not in Article.static_fields()
field_type = get_property_primitive_type(field_name)
if field_type in (int, str, float):
return ArticleFieldCategory(is_json_field=is_json_field, field_name=field_name, **kwargs)
elif field_type == datetime.datetime:
return IntervalCategory(is_json_field=is_json_field, field_name=field_name, **kwargs)
else:
raise ValueError("Did not recognize primitive field type: {} (on {})".format(field_type, field_name))