本文整理汇总了Python中mongoengine.fields.StringField方法的典型用法代码示例。如果您正苦于以下问题:Python fields.StringField方法的具体用法?Python fields.StringField怎么用?Python fields.StringField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongoengine.fields
的用法示例。
在下文中一共展示了fields.StringField方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_model_mismatch
# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import StringField [as 别名]
def test_model_mismatch(self):
""" cannot apply filters for one model to queryset from another """
class FooDoc(Document):
foo = fields.StringField()
class BarDoc(Document):
bar = fields.StringField()
class FooFilter(ModelFilterset):
class Meta:
model = FooDoc
class BarView(ListAPIView):
filter_backends = (MongoFilterBackend,)
filter_class = FooFilter
serializer_class = mock.Mock()
queryset = BarDoc.objects
with self.assertRaises(TypeError):
BarView.as_view()(APIRequestFactory().get("/?foo=Foo"))
示例2: test_model_subclassed
# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import StringField [as 别名]
def test_model_subclassed(self):
""" can apply filters for base model to queryset of derived """
class FooDoc(Document):
meta = { 'allow_inheritance': True}
foo = fields.StringField()
class BarDoc(FooDoc):
bar = fields.StringField()
class FooFilter(ModelFilterset):
class Meta:
model = FooDoc
class BarView(ListAPIView):
filter_backends = (MongoFilterBackend,)
filter_class = FooFilter
serializer_class = mock.Mock()
queryset = BarDoc.objects
BarView.as_view()(APIRequestFactory().get("/?foo=Foo"))
示例3: test_auto_derivatives
# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import StringField [as 别名]
def test_auto_derivatives(self):
class FooField(fields.StringField):
pass
class MockModel(Document):
foo = FooField()
class TestFS(ModelFilterset):
class Meta:
model = MockModel
fs = TestFS()
self.assertEqual(set(fs.filters.keys()), set(['id', 'foo']))
self.assertIsInstance(fs.filters['foo'], filters.CharFilter)
示例4: test_selecting
# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import StringField [as 别名]
def test_selecting(self):
class MockModel(Document):
foo = fields.StringField()
bar = fields.StringField()
baz = fields.StringField()
class TestFS(ModelFilterset):
class Meta:
model = MockModel
fields = ('foo','baz')
fs = TestFS()
self.assertEqual(set(fs.filters.keys()), set(['id', 'foo', 'baz']))
示例5: test_excluding
# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import StringField [as 别名]
def test_excluding(self):
class MockModel(Document):
foo = fields.StringField()
bar = fields.StringField()
baz = fields.StringField()
class TestFS(ModelFilterset):
class Meta:
model = MockModel
exclude = ('bar',)
fs = TestFS()
self.assertEqual(set(fs.filters.keys()), set(['id', 'foo', 'baz']))
self.assertIsInstance(fs.filters['foo'], filters.CharFilter)
示例6: test_redeclaring
# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import StringField [as 别名]
def test_redeclaring(self):
class MockModel(Document):
foo = fields.StringField()
bar = fields.StringField()
baz = fields.StringField()
class TestFS(ModelFilterset):
class Meta:
model = MockModel
bar = filters.IntegerFilter()
fs = TestFS()
self.assertEqual(set(fs.filters.keys()), set(['id', 'foo', 'bar', 'baz']))
self.assertIsInstance(fs.filters['foo'], filters.CharFilter)
self.assertIsInstance(fs.filters['bar'], filters.IntegerFilter)
self.assertIsInstance(fs.filters['baz'], filters.CharFilter)
示例7: test_kwargs
# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import StringField [as 别名]
def test_kwargs(self):
class MockModel(Document):
foo = fields.StringField()
bar = fields.StringField()
baz = fields.StringField()
class TestFS(ModelFilterset):
class Meta:
model = MockModel
kwargs = {
'foo': { 'lookup': 'gte' }
}
fs = TestFS()
self.assertEqual(fs.filters['foo'].lookup_type, 'gte')
示例8: __init__
# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import StringField [as 别名]
def __init__(self, **kwargs):
self.registered = {}
super(BadgesField, self).__init__(StringField(), **kwargs)
示例9: __init__
# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import StringField [as 别名]
def __init__(self, **kwargs):
self.tags = []
super(TagListField, self).__init__(StringField(), **kwargs)