Python peewee.BooleanField() Examples
The following are 4
code examples of peewee.BooleanField().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
peewee
, or try the search function
.
Example #1
Source File: fake_item_ids.py From detdup with MIT License | 6 votes |
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(" "))
Example #2
Source File: validate.py From slim with zlib License | 5 votes |
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
Example #3
Source File: test.py From peewee-db-evolve with GNU Lesser General Public License v3.0 | 5 votes |
def test_add_not_null_constraint_with_records_and_false_default(self): class SomeModel(pw.Model): some_field = pw.BooleanField(null=True) class Meta: database = self.db self.evolve_and_check_noop() SomeModel.create(some_field=None) peeweedbevolve.clear() class SomeModel(pw.Model): some_field = pw.BooleanField(null=False, default=False) class Meta: database = self.db self.evolve_and_check_noop() self.assertEqual(SomeModel.select().first().some_field, False)
Example #4
Source File: test.py From peewee-db-evolve with GNU Lesser General Public License v3.0 | 5 votes |
def test_add_columns_with_false_defaults(self): class SomeModel(pw.Model): class Meta: database = self.db self.evolve_and_check_noop() SomeModel.create(some_field=None) peeweedbevolve.clear() class SomeModel(pw.Model): some_field = pw.BooleanField(null=False, default=False) created_at = pw.DateTimeField(default=datetime.datetime.now) class Meta: database = self.db self.evolve_and_check_noop() self.assertEqual(SomeModel.select().first().some_field, False)