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


Python mongoengine.EmbeddedDocumentField方法代碼示例

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


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

示例1: models

# 需要導入模塊: import mongoengine [as 別名]
# 或者: from mongoengine import EmbeddedDocumentField [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

示例2: convert_field_to_list

# 需要導入模塊: import mongoengine [as 別名]
# 或者: from mongoengine import EmbeddedDocumentField [as 別名]
def convert_field_to_list(field, registry=None):
    base_type = convert_mongoengine_field(field.field, registry=registry)
    if isinstance(base_type, graphene.Field):
        return graphene.List(
            base_type._type,
            description=get_field_description(field, registry),
            required=field.required
        )
    if isinstance(base_type, (graphene.Dynamic)):
        base_type = base_type.get_type()
        if base_type is None:
            return
        base_type = base_type._type

    if graphene.is_node(base_type):
        return base_type._meta.connection_field_class(base_type)

    # Non-relationship field
    relations = (mongoengine.ReferenceField, mongoengine.EmbeddedDocumentField)
    if not isinstance(base_type, (graphene.List, graphene.NonNull)) and not isinstance(
        field.field, relations
    ):
        base_type = type(base_type)

    return graphene.List(
        base_type,
        description=get_field_description(field, registry),
        required=field.required,
    ) 
開發者ID:graphql-python,項目名稱:graphene-mongo,代碼行數:31,代碼來源:converter.py

示例3: convert_field_to_union

# 需要導入模塊: import mongoengine [as 別名]
# 或者: from mongoengine import EmbeddedDocumentField [as 別名]
def convert_field_to_union(field, registry=None):

    _types = []
    for choice in field.choices:
        if isinstance(field, mongoengine.GenericReferenceField):
            _field = mongoengine.ReferenceField(get_document(choice))
        elif isinstance(field, mongoengine.GenericEmbeddedDocumentField):
            _field = mongoengine.EmbeddedDocumentField(choice)

        _field = convert_mongoengine_field(_field, registry)
        _type = _field.get_type()
        if _type:
            _types.append(_type.type)
        else:
            # TODO: Register type auto-matically here.
            pass

    if len(_types) == 0:
        return None

    # XXX: Use uuid to avoid duplicate name
    name = "{}_{}_union_{}".format(
        field._owner_document.__name__,
        field.db_field,
        str(uuid.uuid1()).replace("-", ""),
    )
    Meta = type("Meta", (object,), {"types": tuple(_types)})
    _union = type(name, (graphene.Union,), {"Meta": Meta})
    return graphene.Field(_union) 
開發者ID:graphql-python,項目名稱:graphene-mongo,代碼行數:31,代碼來源:converter.py


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