當前位置: 首頁>>代碼示例>>Python>>正文


Python peewee.BooleanField方法代碼示例

本文整理匯總了Python中peewee.BooleanField方法的典型用法代碼示例。如果您正苦於以下問題:Python peewee.BooleanField方法的具體用法?Python peewee.BooleanField怎麽用?Python peewee.BooleanField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在peewee的用法示例。


在下文中一共展示了peewee.BooleanField方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import BooleanField [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(" ")) 
開發者ID:17zuoye,項目名稱:detdup,代碼行數:24,代碼來源:fake_item_ids.py

示例2: field_class_to_schematics_field

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import BooleanField [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 
開發者ID:fy0,項目名稱:slim,代碼行數:40,代碼來源:validate.py

示例3: test_add_not_null_constraint_with_records_and_false_default

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import BooleanField [as 別名]
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) 
開發者ID:keredson,項目名稱:peewee-db-evolve,代碼行數:16,代碼來源:test.py

示例4: test_add_columns_with_false_defaults

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import BooleanField [as 別名]
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) 
開發者ID:keredson,項目名稱:peewee-db-evolve,代碼行數:16,代碼來源:test.py


注:本文中的peewee.BooleanField方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。