当前位置: 首页>>代码示例>>Python>>正文


Python fields.StringField方法代码示例

本文整理汇总了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")) 
开发者ID:qwiglydee,项目名称:drf-mongo-filters,代码行数:22,代码来源:test_backend.py

示例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")) 
开发者ID:qwiglydee,项目名称:drf-mongo-filters,代码行数:22,代码来源:test_backend.py

示例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) 
开发者ID:qwiglydee,项目名称:drf-mongo-filters,代码行数:16,代码来源:test_filtersets.py

示例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'])) 
开发者ID:qwiglydee,项目名称:drf-mongo-filters,代码行数:15,代码来源:test_filtersets.py

示例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) 
开发者ID:qwiglydee,项目名称:drf-mongo-filters,代码行数:16,代码来源:test_filtersets.py

示例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) 
开发者ID:qwiglydee,项目名称:drf-mongo-filters,代码行数:17,代码来源:test_filtersets.py

示例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') 
开发者ID:qwiglydee,项目名称:drf-mongo-filters,代码行数:16,代码来源:test_filtersets.py

示例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) 
开发者ID:opendatateam,项目名称:udata,代码行数:5,代码来源:badges_field.py

示例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) 
开发者ID:opendatateam,项目名称:udata,代码行数:5,代码来源:taglist_field.py


注:本文中的mongoengine.fields.StringField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。