当前位置: 首页>>代码示例>>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;未经允许,请勿转载。