本文整理汇总了Python中peewee.CharField方法的典型用法代码示例。如果您正苦于以下问题:Python peewee.CharField方法的具体用法?Python peewee.CharField怎么用?Python peewee.CharField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类peewee
的用法示例。
在下文中一共展示了peewee.CharField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_model
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import CharField [as 别名]
def _create_model(self, db, table_prefix):
"""
创建数据model
"""
meta_dict = {
"database": db,
"table_name": table_prefix + "_" + "Report"
}
meta = type("Meta", (object, ), meta_dict)
model_dict = {
"id": peewee.AutoField(),
"plugin_name": peewee.CharField(max_length=63),
"description": peewee.TextField(),
"rasp_result_list": self.LongTextField(),
"payload_seq": peewee.CharField(unique=True, max_length=63),
"message": peewee.TextField(),
"time": peewee.IntegerField(default=common.get_timestamp),
"upload": peewee.IntegerField(default=0),
"Meta": meta
}
self.Report = type("Report", (peewee.Model, ), model_dict)
return self.Report
示例2: _create_model
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import CharField [as 别名]
def _create_model(self, db, table_prefix):
"""
创建数据model
"""
meta_dict = {
"database": db,
"table_name": "Config"
}
meta = type("Meta", (object, ), meta_dict)
model_dict = {
"host_port_hash": peewee.CharField(primary_key=True, max_length=63),
"host_port": peewee.TextField(),
"config_json": peewee.TextField(),
"Meta": meta
}
self.Config = type("Config", (peewee.Model, ), model_dict)
return self.Config
示例3: _create_model
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import CharField [as 别名]
def _create_model(self, db, table_prefix):
"""
创建数据model
"""
meta_dict = {
"database": db,
"table_name": table_prefix + "_" + "ResultList"
}
meta = type("Meta", (object, ), meta_dict)
model_dict = {
"id": peewee.AutoField(),
"data": self.LongTextField(),
# utf8mb4 编码下 1 char = 4 bytes,会导致peewee创建过长的列导致MariaDB产生 1071, Specified key was too long; 错误, max_length不使用255
"data_hash": peewee.CharField(unique=True, max_length=63),
# scan_status含义: 未扫描:0, 已扫描:1, 正在扫描:2, 扫描中出现错误: 3
"scan_status": peewee.IntegerField(default=0),
"time": peewee.IntegerField(default=common.get_timestamp),
"Meta": meta
}
self.ResultList = type("ResultList", (peewee.Model, ), model_dict)
return self.ResultList
示例4: test_has_index
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import CharField [as 别名]
def test_has_index(self):
"""Check method returns False and True when either table or index
does not exist"""
from taxadb.schema import BaseModel
import peewee as pw
class FooBar(BaseModel):
id = pw.IntegerField(null=False)
name = pw.CharField()
idx = FooBar.index(FooBar.name, name='name')
FooBar.add_index(idx)
obj = self._buildTaxaDBObject(TaxaDB)
# Test returns False
self.assertFalse(FooBar.has_index(name='foo'))
FooBar.create_table(fail_silently=True)
self.assertFalse(FooBar.has_index(name='foo'))
self.assertFalse(FooBar.has_index())
self.assertFalse(FooBar.has_index(columns=10))
# Test returns True
self.assertTrue(FooBar.has_index(name='name'))
FooBar.drop_table()
示例5: test_order_by_inheritance
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import CharField [as 别名]
def test_order_by_inheritance():
class Base(TestModel):
created = DateTimeField()
class Meta:
order_by = ('-created',)
class Foo(Base):
data = CharField()
class Bar(Base):
val = IntegerField()
class Meta:
order_by = ('-val',)
foo_order_by = Foo._meta.order_by[0]
assert isinstance(foo_order_by, Field)
assert foo_order_by.model_class is Foo
assert foo_order_by.name == 'created'
bar_order_by = Bar._meta.order_by[0]
assert isinstance(bar_order_by, Field)
assert bar_order_by.model_class is Bar
assert bar_order_by.name == 'val'
示例6: test_add_not_null_constraint_with_records_and_default_which_is_function
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import CharField [as 别名]
def test_add_not_null_constraint_with_records_and_default_which_is_function(self):
class SomeModel(pw.Model):
some_field = pw.CharField(null=True)
class Meta:
database = self.db
self.evolve_and_check_noop()
SomeModel.create(some_field=None)
peeweedbevolve.clear()
def woot():
return 'woot'
class SomeModel(pw.Model):
some_field = pw.CharField(null=False, default=woot)
class Meta:
database = self.db
self.evolve_and_check_noop()
self.assertEqual(SomeModel.select().first().some_field, 'woot')
示例7: test_reorder_multi_index
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import CharField [as 别名]
def test_reorder_multi_index(self):
class SomeModel(pw.Model):
some_field = pw.CharField(null=True)
class Meta:
database = self.db
indexes = (
(('id', 'some_field'), False),
)
self.evolve_and_check_noop()
self.assertEqual(sorted(peeweedbevolve.normalize_indexes(peeweedbevolve.get_indexes_by_table(self.db,'somemodel'))), [(u'somemodel', (u'id',), True), (u'somemodel', (u'id',u'some_field'), False)])
peeweedbevolve.clear()
class SomeModel(pw.Model):
some_field = pw.CharField(null=True)
class Meta:
database = self.db
indexes = (
(('some_field', 'id'), False),
)
self.evolve_and_check_noop()
self.assertEqual(sorted(peeweedbevolve.normalize_indexes(peeweedbevolve.get_indexes_by_table(self.db,'somemodel'))), [(u'somemodel', (u'id',), True), (u'somemodel', (u'some_field',u'id'), False)])
示例8: test_drop_column_default
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import CharField [as 别名]
def test_drop_column_default(self):
class SomeModel(pw.Model):
some_field = pw.CharField(null=True, default='woot2')
class Meta:
database = self.db
self.evolve_and_check_noop()
model = SomeModel.create()
self.assertEqual(model.some_field, 'woot2')
peeweedbevolve.clear()
class SomeModel(pw.Model):
some_field = pw.CharField(null=True)
class Meta:
database = self.db
self.evolve_and_check_noop()
model = SomeModel.create()
self.assertEqual(model.some_field, None)
self.assertEqual(SomeModel.get(SomeModel.id==model.id).some_field, None)
示例9: test_dont_drop_table
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import CharField [as 别名]
def test_dont_drop_table(self):
class SomeModel(pw.Model):
some_field = pw.CharField(null=True)
class Meta:
database = self.db
self.evolve_and_check_noop()
SomeModel.create(some_field='woot')
peeweedbevolve.clear()
class SomeModel(pw.Model):
some_field = pw.CharField(null=True)
class Meta:
database = self.db
evolve = False
self.evolve_and_check_noop()
# doesn't fail because table is still there
SomeModel.create(some_field='woot2')
示例10: test_dont_add_column
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import CharField [as 别名]
def test_dont_add_column(self):
class SomeModel(pw.Model):
some_field = pw.CharField(null=True)
class Meta:
database = self.db
self.evolve_and_check_noop()
peeweedbevolve.clear()
class SomeModel(pw.Model):
some_field = pw.CharField(null=True)
some_other_field = pw.CharField(null=False)
class Meta:
database = self.db
evolve = False
self.evolve_and_check_noop()
# should not fail because the not-null column wasn't added
SomeModel.create(some_field='woot')
示例11: __init__
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import CharField [as 别名]
def __init__(self, data_model):
self.data_model = data_model
self.data_model.fake_item_ids_store = self
assert self.data_model.cache_dir, "FakeItemIds need cache_dir from data_model!"
sqlite_path = os.path.join(self.data_model.cache_dir, "fake_item_ids_store.db")
sqlite_database = SqliteDatabase(sqlite_path, check_same_thread=False)
class FakeItemIdsStore(Model):
is_deleted = BooleanField(default=False) # mark processed or duplicated items
item_id = CharField()
item_content_json = TextField()
created_at = TimeField(default=datetime.datetime.now)
class Meta:
database = sqlite_database
self.storage = FakeItemIdsStore
if not self.storage.table_exists():
self.storage.create_table()
sqlite_database.create_index(self.storage, "is_deleted item_id".split(" "))
示例12: test_table_exists_failed
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import CharField [as 别名]
def test_table_exists_failed(self):
"""Check the method throws SystemExit if a table does not exist"""
from taxadb.schema import BaseModel
import peewee as pw
class NotFound(BaseModel):
id = pw.IntegerField(null=False)
name = pw.CharField()
obj = self._buildTaxaDBObject(TaxaDB)
with self.assertRaises(SystemExit):
obj.check_table_exists(NotFound)
示例13: logging_env_column
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import CharField [as 别名]
def logging_env_column(db, migrator):
m.migrate(
migrator.add_column('log', 'env', pw.CharField(null=True))
)
示例14: test_related_name_collision
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import CharField [as 别名]
def test_related_name_collision(flushdb):
class Foo(TestModel):
f1 = CharField()
with pytest.raises(AttributeError):
class FooRel(TestModel):
foo = ForeignKeyField(Foo, related_name='f1')
示例15: test_meta_remove_field
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import CharField [as 别名]
def test_meta_remove_field():
class _Model(Model):
title = CharField(max_length=25)
content = TextField(default='')
_Model._meta.remove_field('content')
assert 'content' not in _Model._meta.fields
assert 'content' not in _Model._meta.sorted_field_names
assert [f.name for f in _Model._meta.sorted_fields] == ['id', 'title']