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