本文整理汇总了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])
示例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])
示例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
示例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
示例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
示例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)
示例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