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


Python fields.ListField方法代码示例

本文整理汇总了Python中mongoengine.fields.ListField方法的典型用法代码示例。如果您正苦于以下问题:Python fields.ListField方法的具体用法?Python fields.ListField怎么用?Python fields.ListField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mongoengine.fields的用法示例。


在下文中一共展示了fields.ListField方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: filter_for_field

# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import ListField [as 别名]
def filter_for_field(cls, name, field, args):
        if args is None:
            args = {}

        if isinstance(field, mongo_fields.ListField):
            field = field.field

        flt_cls = cls.find_flt_class(field)

        assert flt_cls is not None, (
            'no filter mapping for %(fld_cls)s %(fld_name)s. please exclude the field, define filter, or adjust %(self_cls)s.filter_mapping' % {
                'fld_cls': str(field.__class__),
                'fld_name': name,
                'fld': repr(field),
                'self_cls': str(cls)
            })

        return flt_cls(**args) 
开发者ID:qwiglydee,项目名称:drf-mongo-filters,代码行数:20,代码来源:filtersets.py

示例2: test_field_options

# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import ListField [as 别名]
def test_field_options(self):
        class TestSerializer(DocumentSerializer):
            class Meta:
                model = FieldOptionsModel
                fields = '__all__'

        expected = dedent("""
            TestSerializer():
                id = ObjectIdField(read_only=True)
                required_field = IntegerField(required=True)
                int_null_field = IntegerField(allow_null=True, required=False)
                string_null_field = CharField(allow_blank=True, allow_null=True, required=False)
                required_list_field = ListField(allow_empty=False, child=IntegerField(required=False), required=True)
                non_required_list_field = ListField(child=IntegerField(required=False), required=False)
                required_dict_field = DictField(allow_empty=False, required=True)
                choices_field = ChoiceField(choices=(('red', 'Red'), ('blue', 'Blue'), ('green', 'Green')), required=False)
                length_limit_field = CharField(max_length=12, min_length=3, required=False)
                value_limit_field = IntegerField(max_value=12, min_value=3, required=False)
                decimal_field = DecimalField(decimal_places=4, max_digits=8, max_value=9999, required=False)
        """)

        assert repr(TestSerializer()) == expected 
开发者ID:umutbozkurt,项目名称:django-rest-framework-mongoengine,代码行数:24,代码来源:test_basic.py

示例3: test_references

# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import ListField [as 别名]
def test_references(self):
        class TestSerializer(DocumentSerializer):
            class Meta:
                model = RefFieldsDoc
                fields = '__all__'

        # order is broken
        expected = dedent("""
            TestSerializer():
                id = ObjectIdField(read_only=True)
                ref_list = ListField(child=ReferenceField(queryset=ReferencedDoc.objects, required=False), required=False)
                ref = ReferenceField(queryset=ReferencedDoc.objects, required=False)
                dbref = ReferenceField(queryset=ReferencedDoc.objects, required=False)
                cached = ReferenceField(queryset=ReferencedDoc.objects, required=False)
                generic = GenericReferenceField(required=False)
        """)
        assert repr(TestSerializer()) == expected 
开发者ID:umutbozkurt,项目名称:django-rest-framework-mongoengine,代码行数:19,代码来源:test_reference.py

示例4: test_basic

# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import ListField [as 别名]
def test_basic(self):
        class TestSerializer(DocumentSerializer):
            class Meta:
                model = BasicCompoundDoc
                fields = '__all__'

        expected = dedent("""
            TestSerializer():
                id = ObjectIdField(read_only=True)
                list_field = ListField(required=False)
                int_list_field = ListField(child=IntegerField(required=False), required=False)
                dict_field = DictField(required=False)
                int_dict_field = DictField(child=IntegerField(required=False), required=False)
                int_map_field = DictField(child=IntegerField(required=False), required=False)
        """)
        assert repr(TestSerializer()) == expected 
开发者ID:umutbozkurt,项目名称:django-rest-framework-mongoengine,代码行数:18,代码来源:test_compound.py

示例5: build_compound_field

# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import ListField [as 别名]
def build_compound_field(self, field_name, model_field, child_field):
        if isinstance(model_field, me_fields.ListField):
            field_class = drf_fields.ListField
        elif isinstance(model_field, me_fields.DictField):
            field_class = drfm_fields.DictField
        else:
            return self.build_unknown_field(field_name, model_field.owner_document)

        field_kwargs = get_field_kwargs(field_name, model_field)
        field_kwargs.pop('model_field', None)

        if child_field is not None:
            field_kwargs['child'] = child_field

        return field_class, field_kwargs 
开发者ID:umutbozkurt,项目名称:django-rest-framework-mongoengine,代码行数:17,代码来源:serializers.py

示例6: test_nested

# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import ListField [as 别名]
def test_nested(self):
        class TestSerializer(DocumentSerializer):
            class Meta:
                model = NestedCompoundDoc
                fields = '__all__'

        expected = dedent("""
            TestSerializer():
                id = ObjectIdField(read_only=True)
                dict_list_field = ListField(child=DictField(required=False), required=False)
                list_dict_field = DictField(child=ListField(required=False), required=False)
                list_dict_list_field = ListField(child=DictField(child=ListField(required=False), required=False), required=False)
        """)
        assert repr(TestSerializer()) == expected 
开发者ID:umutbozkurt,项目名称:django-rest-framework-mongoengine,代码行数:16,代码来源:test_compound.py

示例7: test_validation_passing

# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import ListField [as 别名]
def test_validation_passing(self):
        serializer = ValidatingSerializer(data={'int_list_field': [3, 4, 5]})
        assert serializer.is_valid(), serializer.errors


# Mongoengine's ListField has a specific meaning of required argument
# Thus, we have to test that it's compatible with DRF's ListField 
开发者ID:umutbozkurt,项目名称:django-rest-framework-mongoengine,代码行数:9,代码来源:test_compound.py

示例8: test_parsing

# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import ListField [as 别名]
def test_parsing(self):
        input_data = {
            'required_list': []
        }
        serializer = RequiredListSerializer(data=input_data)
        serializer.is_valid()
        assert serializer.errors['required_list'] == [u'This list may not be empty.']


# Check that ListField is allowed to be empty, if required=False 
开发者ID:umutbozkurt,项目名称:django-rest-framework-mongoengine,代码行数:12,代码来源:test_compound.py

示例9: recursive_save

# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import ListField [as 别名]
def recursive_save(self, validated_data, instance=None):
        """
        Recursively traverses validated_data and creates EmbeddedDocuments
        of the appropriate subtype from them.

        Returns Mongonengine model instance.
        """
        # me_data is an analogue of validated_data, but contains
        # mongoengine EmbeddedDocument instances for nested data structures
        # instead of OrderedDicts.
        #
        # For example:
        # validated_data = {'id:, "1", 'embed': OrderedDict({'a': 'b'})}
        # me_data = {'id': "1", 'embed': <EmbeddedDocument>}
        me_data = dict()

        for key, value in validated_data.items():
            try:
                field = self.fields[key]

                # for EmbeddedDocumentSerializers, call recursive_save
                if isinstance(field, EmbeddedDocumentSerializer):
                    me_data[key] = field.recursive_save(value) if value is not None else value # issue when the value is none 

                # same for lists of EmbeddedDocumentSerializers i.e.
                # ListField(EmbeddedDocumentField) or EmbeddedDocumentListField
                elif ((isinstance(field, serializers.ListSerializer) or
                       isinstance(field, serializers.ListField)) and
                      isinstance(field.child, EmbeddedDocumentSerializer)):
                    me_data[key] = []
                    for datum in value:
                        me_data[key].append(field.child.recursive_save(datum))

                # same for dicts of EmbeddedDocumentSerializers (or, speaking
                # in Mongoengine terms, MapField(EmbeddedDocument(Embed))
                elif (isinstance(field, drfm_fields.DictField) and
                      hasattr(field, "child") and
                      isinstance(field.child, EmbeddedDocumentSerializer)):
                    me_data[key] = {}
                    for datum_key, datum_value in value.items():
                        me_data[key][datum_key] = field.child.recursive_save(datum_value)

                # for regular fields just set value
                else:
                    me_data[key] = value

            except KeyError:  # this is dynamic data
                me_data[key] = value

        # create (if needed), save (if needed) and return mongoengine instance
        if not instance:
            instance = self.Meta.model(**me_data)
        else:
            for key, value in me_data.items():
                setattr(instance, key, value)

        if self._saving_instances:
            instance.save()

        return instance 
开发者ID:umutbozkurt,项目名称:django-rest-framework-mongoengine,代码行数:62,代码来源:serializers.py


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