本文整理汇总了Python中peewee.FloatField方法的典型用法代码示例。如果您正苦于以下问题:Python peewee.FloatField方法的具体用法?Python peewee.FloatField怎么用?Python peewee.FloatField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类peewee
的用法示例。
在下文中一共展示了peewee.FloatField方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: field_class_to_schematics_field
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import FloatField [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: test_change_column_type_float_decimal
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import FloatField [as 别名]
def test_change_column_type_float_decimal(self):
class SomeModel(pw.Model):
some_field = pw.FloatField(default=8)
class Meta:
database = self.db
self.evolve_and_check_noop()
model = SomeModel.create()
self.assertEqual(model.some_field, 8)
peeweedbevolve.clear()
class SomeModel(pw.Model):
some_field = pw.DecimalField(default=8)
class Meta:
database = self.db
self.evolve_and_check_noop()
self.assertEqual(SomeModel.select().first().some_field, 8)