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


Python mongoengine.IntField方法代碼示例

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


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

示例1: test_GenericEmbeddedDocumentField

# 需要導入模塊: import mongoengine [as 別名]
# 或者: from mongoengine import IntField [as 別名]
def test_GenericEmbeddedDocumentField(self):
        class Doc(me.Document):
            id = me.StringField(primary_key=True, default='main')
            embedded = me.GenericEmbeddedDocumentField()
        class EmbeddedA(me.EmbeddedDocument):
            field_a = me.StringField(default='field_a_value')
        class EmbeddedB(me.EmbeddedDocument):
            field_b = me.IntField(default=42)
        fields_ = fields_for_model(Doc)
        assert type(fields_['embedded']) is fields.GenericEmbeddedDocument
        class DocSchema(ModelSchema):
            class Meta:
                model = Doc
        doc = Doc(embedded=EmbeddedA())
        dump = DocSchema().dump(doc)
        assert not dump.errors
        assert dump.data == {'embedded': {'field_a': 'field_a_value'}, 'id': 'main'}
        doc.embedded = EmbeddedB()
        doc.save()
        dump = DocSchema().dump(doc)
        assert not dump.errors
        assert dump.data == {'embedded': {'field_b': 42}, 'id': 'main'}
        # TODO: test load ? 
開發者ID:touilleMan,項目名稱:marshmallow-mongoengine,代碼行數:25,代碼來源:test_fields.py

示例2: test_MapField

# 需要導入模塊: import mongoengine [as 別名]
# 或者: from mongoengine import IntField [as 別名]
def test_MapField(self):
        class MappedDoc(me.EmbeddedDocument):
            field = me.StringField()
        class Doc(me.Document):
            id = me.IntField(primary_key=True, default=1)
            map = me.MapField(me.EmbeddedDocumentField(MappedDoc))
            str = me.MapField(me.StringField())
        fields_ = fields_for_model(Doc)
        assert type(fields_['map']) is fields.Map
        class DocSchema(ModelSchema):
            class Meta:
                model = Doc
        doc = Doc(map={'a': MappedDoc(field='A'), 'b': MappedDoc(field='B')},
                  str={'a': 'aaa', 'b': 'bbbb'}).save()
        dump = DocSchema().dump(doc)
        assert not dump.errors
        assert dump.data == {'map': {'a': {'field': 'A'}, 'b': {'field': 'B'}},
                             'str': {'a': 'aaa', 'b': 'bbbb'}, 'id': 1}
        # Try the load
        load = DocSchema().load(dump.data)
        assert not load.errors
        assert load.data.map == doc.map 
開發者ID:touilleMan,項目名稱:marshmallow-mongoengine,代碼行數:24,代碼來源:test_fields.py

示例3: models

# 需要導入模塊: import mongoengine [as 別名]
# 或者: from mongoengine import IntField [as 別名]
def models():

    class HeadTeacher(me.EmbeddedDocument):
        full_name = me.StringField(max_length=255, unique=True, default='noname')

    class Course(me.Document):
        id = me.IntField(primary_key=True)
        name = me.StringField()
        # These are for better model form testing
        cost = me.IntField()
        description = me.StringField()
        level = me.StringField(choices=('Primary', 'Secondary'))
        prereqs = me.DictField()
        started = me.DateTimeField()
        grade = AnotherIntegerField()
        students = me.ListField(me.ReferenceField('Student'))

    class School(me.Document):
        name = me.StringField()
        students = me.ListField(me.ReferenceField('Student'))
        headteacher = me.EmbeddedDocumentField(HeadTeacher)

    class Student(me.Document):
        full_name = me.StringField(max_length=255, unique=True, default='noname')
        age = me.IntField(min_value=10, max_value=99)
        dob = me.DateTimeField(null=True)
        date_created = me.DateTimeField(default=dt.datetime.utcnow,
                                        help_text='date the student was created')
        current_school = me.ReferenceField('School')
        courses = me.ListField(me.ReferenceField('Course'))
        email = me.EmailField(max_length=100)
        profile_uri = me.URLField(max_length=200)

    # So that we can access models with dot-notation, e.g. models.Course
    class _models(object):

        def __init__(self):
            self.HeadTeacher = HeadTeacher
            self.Course = Course
            self.School = School
            self.Student = Student
    return _models() 
開發者ID:touilleMan,項目名稱:marshmallow-mongoengine,代碼行數:44,代碼來源:test_marshmallow_mongoengine.py

示例4: test_ReferenceField

# 需要導入模塊: import mongoengine [as 別名]
# 或者: from mongoengine import IntField [as 別名]
def test_ReferenceField(self):
        class ReferenceDoc(me.Document):
            field = me.IntField(primary_key=True, default=42)
        class Doc(me.Document):
            id = me.StringField(primary_key=True, default='main')
            ref = me.ReferenceField(ReferenceDoc)
        fields_ = fields_for_model(Doc)
        assert type(fields_['ref']) is fields.Reference
        class DocSchema(ModelSchema):
            class Meta:
                model = Doc
        ref_doc = ReferenceDoc().save()
        doc = Doc(ref=ref_doc)
        dump = DocSchema().dump(doc)
        assert not dump.errors
        assert dump.data == {'ref': 42, 'id': 'main'}
        # Try the same with reference document type passed as string
        class DocSchemaRefAsString(Schema):
            id = fields.String()
            ref = fields.Reference('ReferenceDoc')
        dump = DocSchemaRefAsString().dump(doc)
        assert not dump.errors
        assert dump.data == {'ref': 42, 'id': 'main'}
        # Test the field loading
        load = DocSchemaRefAsString().load(dump.data)
        assert not load.errors
        assert type(load.data['ref']) == ReferenceDoc
        # Try invalid loads
        for bad_ref in (1, 'NaN', None):
            dump.data['ref'] = bad_ref
            _, errors = DocSchemaRefAsString().load(dump.data)
            assert errors, bad_ref 
開發者ID:touilleMan,項目名稱:marshmallow-mongoengine,代碼行數:34,代碼來源:test_fields.py

示例5: test_required_with_default

# 需要導入模塊: import mongoengine [as 別名]
# 或者: from mongoengine import IntField [as 別名]
def test_required_with_default(self):
        class Doc(me.Document):
            basic = me.IntField(required=True, default=42)
            cunning = me.BooleanField(required=True, default=False)
        class DocSchema(ModelSchema):
            class Meta:
                model = Doc
        doc, errors = DocSchema().load({})
        assert not errors
        assert doc.basic == 42
        assert doc.cunning is False 
開發者ID:touilleMan,項目名稱:marshmallow-mongoengine,代碼行數:13,代碼來源:test_params.py

示例6: test_sould_int_convert_int

# 需要導入模塊: import mongoengine [as 別名]
# 或者: from mongoengine import IntField [as 別名]
def test_sould_int_convert_int():
    assert_conversion(mongoengine.IntField, graphene.Int) 
開發者ID:graphql-python,項目名稱:graphene-mongo,代碼行數:4,代碼來源:test_converter.py


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