當前位置: 首頁>>代碼示例>>Python>>正文


Python fields.IntegerField方法代碼示例

本文整理匯總了Python中rest_framework.fields.IntegerField方法的典型用法代碼示例。如果您正苦於以下問題:Python fields.IntegerField方法的具體用法?Python fields.IntegerField怎麽用?Python fields.IntegerField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rest_framework.fields的用法示例。


在下文中一共展示了fields.IntegerField方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_range

# 需要導入模塊: from rest_framework import fields [as 別名]
# 或者: from rest_framework.fields import IntegerField [as 別名]
def test_range(self):
        objects = [
            SimpleDoc.objects.create(f_int=3),
            SimpleDoc.objects.create(f_int=5),
            SimpleDoc.objects.create(f_int=7),
            SimpleDoc.objects.create(f_int=11),
            SimpleDoc.objects.create(f_int=13),
        ]

        class FS(Filterset):
            foo = filters.RangeFilter(child=fields.IntegerField(), source='f_int')
            bar = filters.RangeFilter(child=fields.IntegerField(), lookup=('gt','lt'), source='f_int')

        fs = FS({'foo': {'min':5, 'max':11}})
        qs = fs.filter_queryset(SimpleDoc.objects.all())
        self.assertQuerysetDocs(qs, objects[1:4])

        fs = FS({'bar': {'min':5, 'max':11}})
        qs = fs.filter_queryset(SimpleDoc.objects.all())
        self.assertQuerysetDocs(qs, objects[2:3]) 
開發者ID:qwiglydee,項目名稱:drf-mongo-filters,代碼行數:22,代碼來源:test_filtering.py

示例2: test_range_intersect

# 需要導入模塊: from rest_framework import fields [as 別名]
# 或者: from rest_framework.fields import IntegerField [as 別名]
def test_range_intersect(self):
        objects = [
            SimpleDoc.objects.create(f_rng_beg=1, f_rng_end=3),
            SimpleDoc.objects.create(f_rng_beg=2, f_rng_end=4), # 4-6
            SimpleDoc.objects.create(f_rng_beg=3, f_rng_end=5), # 4-6
            SimpleDoc.objects.create(f_rng_beg=4, f_rng_end=6), # 4-6
            SimpleDoc.objects.create(f_rng_beg=5, f_rng_end=7), # 4-6
            SimpleDoc.objects.create(f_rng_beg=6, f_rng_end=8), # 4-6
            SimpleDoc.objects.create(f_rng_beg=7, f_rng_end=9)
        ]

        class FS(Filterset):
            foo = filters.IntersectRangeFilter(('f_rng_beg','f_rng_end'), child=fields.IntegerField())

        fs = FS({'foo': {'min':4, 'max':6}})
        qs = fs.filter_queryset(SimpleDoc.objects.all())
        self.assertQuerysetDocs(qs, objects[1:-1]) 
開發者ID:qwiglydee,項目名稱:drf-mongo-filters,代碼行數:19,代碼來源:test_filtering.py

示例3: get_paginator_serializer

# 需要導入模塊: from rest_framework import fields [as 別名]
# 或者: from rest_framework.fields import IntegerField [as 別名]
def get_paginator_serializer(self, view, child_serializer_class):
        class BaseFakeListSerializer(serializers.Serializer):
            results = child_serializer_class(many=True)

        class FakePrevNextListSerializer(BaseFakeListSerializer):
            next = URLField()
            previous = URLField()

        # Validate if the view has a pagination_class
        if not (hasattr(view, 'pagination_class')) or view.pagination_class is None:
            return BaseFakeListSerializer

        pager = view.pagination_class
        if hasattr(pager, 'default_pager'):
            # Must be a ProxyPagination
            pager = pager.default_pager

        if issubclass(pager, (PageNumberPagination, LimitOffsetPagination)):
            class FakeListSerializer(FakePrevNextListSerializer):
                count = IntegerField()
            return FakeListSerializer
        elif issubclass(pager, CursorPagination):
            return FakePrevNextListSerializer

        return BaseFakeListSerializer 
開發者ID:limdauto,項目名稱:drf_openapi,代碼行數:27,代碼來源:entities.py

示例4: test_custom_nested

# 需要導入模塊: from rest_framework import fields [as 別名]
# 或者: from rest_framework.fields import IntegerField [as 別名]
def test_custom_nested(self):
        class CustomReferencing(Serializer):
            foo = IntegerField()

        class TestSerializer(DocumentSerializer):
            serializer_reference_nested = CustomReferencing

            class Meta:
                model = ReferencingDoc
                fields = '__all__'
                depth = 1

        expected = dedent("""
            TestSerializer():
                id = ObjectIdField(read_only=True)
                ref = NestedSerializer(read_only=True):
                    foo = IntegerField()
        """)
        assert repr(TestSerializer()) == expected 
開發者ID:umutbozkurt,項目名稱:django-rest-framework-mongoengine,代碼行數:21,代碼來源:test_reference.py

示例5: test_mapping

# 需要導入模塊: from rest_framework import fields [as 別名]
# 或者: from rest_framework.fields import IntegerField [as 別名]
def test_mapping(self):
        class TestSerializer(DocumentSerializer):
            class Meta:
                model = DumbDocument
                fields = '__all__'

        expected = dedent("""
            TestSerializer():
                id = ObjectIdField(read_only=True)
                name = CharField(required=False)
                foo = IntegerField(required=False)
        """)

        # better output then self.assertEqual()
        assert repr(TestSerializer()) == expected 
開發者ID:umutbozkurt,項目名稱:django-rest-framework-mongoengine,代碼行數:17,代碼來源:test_dumb.py

示例6: test_serializer_get_fields

# 需要導入模塊: from rest_framework import fields [as 別名]
# 或者: from rest_framework.fields import IntegerField [as 別名]
def test_serializer_get_fields(self):
        obj = SearchQuerySet().filter(lastname="Foreman")[0]
        serializer = self.serializer1(instance=obj)
        fields = serializer.get_fields()

        self.assertIsInstance(fields, dict)
        self.assertIsInstance(fields["integer_field"], IntegerField)
        self.assertIsInstance(fields["text"], CharField)
        self.assertIsInstance(fields["firstname"], CharField)
        self.assertIsInstance(fields["lastname"], CharField)
        self.assertIsInstance(fields["autocomplete"], CharField) 
開發者ID:rhblind,項目名稱:drf-haystack,代碼行數:13,代碼來源:test_serializers.py

示例7: setUp

# 需要導入模塊: from rest_framework import fields [as 別名]
# 或者: from rest_framework.fields import IntegerField [as 別名]
def setUp(self):
        MockPersonIndex().reindex()
        MockPetIndex().reindex()

        class Serializer1(HaystackSerializer):

            integer_field = serializers.IntegerField()
            city = serializers.SerializerMethodField()

            class Meta:
                index_classes = [MockPersonIndex]
                fields = ["text", "firstname", "lastname", "autocomplete"]

            def get_integer_field(self, instance):
                return 1

            def get_city(self, instance):
                return "Declared overriding field"

        class Serializer2(HaystackSerializer):

            class Meta:
                index_classes = [MockPersonIndex]
                exclude = ["firstname"]

        class Serializer3(HaystackSerializer):

            class Meta:
                index_classes = [MockPersonIndex]
                fields = ["text", "firstname", "lastname", "autocomplete"]
                ignore_fields = ["autocomplete"]

        class Serializer7(HaystackSerializer):

            class Meta:
                index_classes = [MockPetIndex]

        class ViewSet1(HaystackViewSet):
            serializer_class = Serializer1

            class Meta:
                index_models = [MockPerson]

        self.serializer1 = Serializer1
        self.serializer2 = Serializer2
        self.serializer3 = Serializer3
        self.serializer7 = Serializer7
        self.view1 = ViewSet1 
開發者ID:rhblind,項目名稱:drf-haystack,代碼行數:50,代碼來源:test_serializers.py


注:本文中的rest_framework.fields.IntegerField方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。