本文整理匯總了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)