當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。