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


Python fields.BaseField方法代碼示例

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


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

示例1: test_custom_type

# 需要導入模塊: from mongoengine import fields [as 別名]
# 或者: from mongoengine.fields import BaseField [as 別名]
def test_custom_type(self):
        class FooField(fields.BaseField):
            pass

        class MockModel(Document):
            foo = FooField()

        class TestFS(ModelFilterset):
            filters_mapping = {
                FooField: filters.CharFilter
            }
            class Meta:
                model = MockModel
        fs = TestFS()
        self.assertEqual(set(fs.filters.keys()), set(['id', 'foo'])) 
開發者ID:qwiglydee,項目名稱:drf-mongo-filters,代碼行數:17,代碼來源:test_filtersets.py

示例2: register

# 需要導入模塊: from mongoengine import fields [as 別名]
# 或者: from mongoengine.fields import BaseField [as 別名]
def register(self, key, dbtype):
        '''Register a DB type to add constraint on a given extra key'''
        if not issubclass(dbtype, (BaseField, EmbeddedDocument)):
            msg = 'ExtrasField can only register MongoEngine fields'
            raise TypeError(msg)
        self.registered[key] = dbtype 
開發者ID:opendatateam,項目名稱:udata,代碼行數:8,代碼來源:extras_fields.py

示例3: test_validate_custom_type

# 需要導入模塊: from mongoengine import fields [as 別名]
# 或者: from mongoengine.fields import BaseField [as 別名]
def test_validate_custom_type(self):
        class Tester(db.Document):
            extras = db.ExtrasField()

        @Tester.extras('test')
        class Custom(BaseField):
            def validate(self, value):
                if not isinstance(value, dict):
                    raise db.ValidationError('Should be a dict instance')

        tester = Tester(extras={'test': {}})
        tester.validate() 
開發者ID:opendatateam,項目名稱:udata,代碼行數:14,代碼來源:test_model.py

示例4: smart_repr

# 需要導入模塊: from mongoengine import fields [as 別名]
# 或者: from mongoengine.fields import BaseField [as 別名]
def smart_repr(value):
    if isinstance(value, QuerySet):
        return manager_repr(value)

    if isinstance(value, BaseField):
        return mongo_field_repr(value)

    if isinstance(value, BaseDocument):
        return mongo_field_repr(value)

    if isinstance(value, Field):
        return field_repr(value)

    value = repr(value)

    # Representations like u'help text'
    # should simply be presented as 'help text'
    value = uni_lit_re.sub("'\\1'", value)

    # Representations like
    # <django.core.validators.RegexValidator object at 0x1047af050>
    # Should be presented as
    # <django.core.validators.RegexValidator object>
    value = re.sub(' at 0x[0-9a-f]{4,32}>', '>', value)

    return value 
開發者ID:umutbozkurt,項目名稱:django-rest-framework-mongoengine,代碼行數:28,代碼來源:repr.py


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