本文整理匯總了Python中peewee.Field方法的典型用法代碼示例。如果您正苦於以下問題:Python peewee.Field方法的具體用法?Python peewee.Field怎麽用?Python peewee.Field使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類peewee
的用法示例。
在下文中一共展示了peewee.Field方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: field_class_to_schematics_field
# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import Field [as 別名]
def field_class_to_schematics_field(field: peewee.Field) -> BaseType:
if isinstance(field, peewee.ForeignKeyField):
field = field.rel_field
kwargs = {}
# 檢查是否 require
if not ((field.default is not None) or field.null or field.sequence or isinstance(field, peewee.AutoField)):
kwargs['required'] = True
if field.help_text:
kwargs['metadata'] = {'description': field.help_text}
if isinstance(field, peewee.IntegerField):
return IntType(**kwargs)
elif isinstance(field, peewee.FloatField):
return FloatType(**kwargs)
elif isinstance(field, (PG_JSONField, PG_BinaryJSONField, SQLITE_JSONField)):
# 注意 SQLITE_JSONField 是一個 _StringField 所以要提前
return JSONType(**kwargs)
# HStore 貌似才應該對應 dict,json可以對應任意類型
# return JSONDictType(StringType, **kwargs)
elif isinstance(field, peewee.DateTimeField):
return DateTimeType(**kwargs)
elif isinstance(field, peewee.DateField):
return DateType(**kwargs)
elif isinstance(field, peewee._StringField):
return StringType(**kwargs)
elif isinstance(field, peewee.BooleanField):
return BooleanType(**kwargs)
elif isinstance(field, peewee.BlobField):
return BlobType(**kwargs)
elif isinstance(field, PG_ArrayField):
field: PG_ArrayField
return JSONListType(field_class_to_schematics_field(field._ArrayField__field), **kwargs)
# noinspection PyProtectedMember
示例2: _add_field_hook
# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import Field [as 別名]
def _add_field_hook():
init = pw.Field.__init__
def _init(*args, **kwargs):
self = args[0]
if 'aka' in kwargs:
akas = kwargs['aka']
if hasattr(akas, 'lower'):
akas = [akas]
self.akas = akas
del kwargs['aka']
init(*args, **kwargs)
pw.Field.__init__ = _init
示例3: order
# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import Field [as 別名]
def order(self):
if self.sort_field and isinstance(self.sort_field, Field):
if self.sort_order and self.sort_field:
return self.sort_field
elif not self.sort_order and self.sort_field:
return -self.sort_field
elif self.sort_field:
return self.sort_field
return None