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


Python fields.ReferenceField方法代码示例

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


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

示例1: test_references

# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import ReferenceField [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

示例2: test_recursive

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

        expected = dedent("""
            TestSerializer():
                id = ObjectIdField(read_only=True)
                ref = NestedSerializer(read_only=True):
                    id = ObjectIdField(read_only=True)
                    ref = NestedSerializer(read_only=True):
                        id = ObjectIdField(read_only=True)
                        ref = NestedSerializer(read_only=True):
                            id = ObjectIdField(read_only=True)
                            ref = ReferenceField(queryset=RecursiveReferencingDoc.objects, required=False)
        """)
        assert repr(TestSerializer()) == expected 
开发者ID:umutbozkurt,项目名称:django-rest-framework-mongoengine,代码行数:21,代码来源:test_reference.py

示例3: test_custom_field

# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import ReferenceField [as 别名]
def test_custom_field(self):
        class CustomReferencing(ReferenceField):
            pass

        class TestSerializer(DocumentSerializer):
            serializer_reference_field = CustomReferencing

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

        expected = dedent("""
            TestSerializer():
                id = ObjectIdField(read_only=True)
                ref = ReferenceField(queryset=ReferencedDoc.objects, required=False)
        """)
        assert repr(TestSerializer()) == expected 
开发者ID:umutbozkurt,项目名称:django-rest-framework-mongoengine,代码行数:20,代码来源:test_reference.py

示例4: test_custom_display_value

# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import ReferenceField [as 别名]
def test_custom_display_value(self):
        class TestField(ReferenceField):
            def display_value(self, instance):
                return 'My %s Color' % (instance.name)

        class TestSerializer(DocumentSerializer):
            color = TestField(queryset=DisplayableReferencedModel.objects.all())

            class Meta:
                model = DisplayableReferencingModel
                fields = '__all__'

        serializer = TestSerializer()
        expected = OrderedDict([(self.ids[0], 'My Red Color'),
                                (self.ids[1], 'My Green Color'),
                                (self.ids[2], 'My Blue Color')])
        assert serializer.fields['color'].choices == expected 
开发者ID:umutbozkurt,项目名称:django-rest-framework-mongoengine,代码行数:19,代码来源:test_reference.py

示例5: test_init_with_model

# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import ReferenceField [as 别名]
def test_init_with_model(self):
        ReferenceField(ReferencedDoc) 
开发者ID:umutbozkurt,项目名称:django-rest-framework-mongoengine,代码行数:4,代码来源:test_reference.py

示例6: test_init_with_queryset

# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import ReferenceField [as 别名]
def test_init_with_queryset(self):
        ReferenceField(queryset=ReferencedDoc.objects.all()) 
开发者ID:umutbozkurt,项目名称:django-rest-framework-mongoengine,代码行数:4,代码来源:test_reference.py

示例7: test_input

# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import ReferenceField [as 别名]
def test_input(self):
        field = ReferenceField(ReferencedDoc)
        instance = ReferencedDoc.objects.create(name="foo")
        ref = instance.to_dbref()
        assert field.to_internal_value(str(instance.id)) == ref
        assert field.to_internal_value({'_id': str(instance.id)}) == ref 
开发者ID:umutbozkurt,项目名称:django-rest-framework-mongoengine,代码行数:8,代码来源:test_reference.py

示例8: test_output

# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import ReferenceField [as 别名]
def test_output(self):
        field = ReferenceField(ReferencedDoc)
        instance = ReferencedDoc.objects.create(name="foo")
        strid = str(instance.id)
        ref = instance.to_dbref()
        assert field.to_representation(instance) == strid
        assert field.to_representation(ref) == strid 
开发者ID:umutbozkurt,项目名称:django-rest-framework-mongoengine,代码行数:9,代码来源:test_reference.py

示例9: test_input_other

# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import ReferenceField [as 别名]
def test_input_other(self):
        field = ReferenceField(OtherReferencedDoc)
        instance = OtherReferencedDoc.objects.create(name="foo")
        ref = instance.to_dbref()
        assert field.to_internal_value(str(instance.id)) == ref
        assert field.to_internal_value({'_id': str(instance.id)}) == ref 
开发者ID:umutbozkurt,项目名称:django-rest-framework-mongoengine,代码行数:8,代码来源:test_reference.py

示例10: test_shallow

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

        expected = dedent("""
            TestSerializer():
                id = ObjectIdField(read_only=True)
                ref = ReferenceField(queryset=ReferencedDoc.objects, required=False)
        """)
        assert repr(TestSerializer()) == expected 
开发者ID:umutbozkurt,项目名称:django-rest-framework-mongoengine,代码行数:15,代码来源:test_reference.py


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