本文整理汇总了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']))
示例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
示例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()
示例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