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


Python OrderedDict.update方法代碼示例

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


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

示例1: _merge_fields_and_pk

# 需要導入模塊: from rest_framework.compat import OrderedDict [as 別名]
# 或者: from rest_framework.compat.OrderedDict import update [as 別名]
def _merge_fields_and_pk(pk, fields):
    fields_and_pk = OrderedDict()
    fields_and_pk['pk'] = pk
    fields_and_pk[pk.name] = pk
    fields_and_pk.update(fields)

    return fields_and_pk
開發者ID:32footsteps,項目名稱:SpecialCollectionsProject,代碼行數:9,代碼來源:model_meta.py

示例2: get_field_info

# 需要導入模塊: from rest_framework.compat import OrderedDict [as 別名]
# 或者: from rest_framework.compat.OrderedDict import update [as 別名]
def get_field_info(model):
    """
    Given a model class, returns a `FieldInfo` instance containing metadata
    about the various field types on the model.
    """
    # Deal with the primary key.
    pk = model.id if not issubclass(model, mongoengine.EmbeddedDocument) else None

    # Deal with regular fields.
    fields = OrderedDict()

    for field_name in model._fields_ordered:
        fields[field_name] = model._fields[field_name]

    # Deal with forward relationships.
    # Pass forward relations since there is no relations on mongodb
    forward_relations = OrderedDict()

    # Deal with reverse relationships.
    # Pass reverse relations since there is no relations on mongodb
    reverse_relations = OrderedDict()

    # Shortcut that merges both regular fields and the pk,
    # for simplifying regular field lookup.
    fields_and_pk = OrderedDict()
    fields_and_pk["pk"] = pk
    fields_and_pk[getattr(pk, "name", "pk")] = pk
    fields_and_pk.update(fields)

    # Shortcut that merges both forward and reverse relationships

    relations = OrderedDict(list(forward_relations.items()) + list(reverse_relations.items()))

    return FieldInfo(pk, fields, forward_relations, reverse_relations, fields_and_pk, relations)
開發者ID:nicolascine,項目名稱:django-rest-framework-mongoengine,代碼行數:36,代碼來源:utils.py

示例3: to_representation

# 需要導入模塊: from rest_framework.compat import OrderedDict [as 別名]
# 或者: from rest_framework.compat.OrderedDict import update [as 別名]
 def to_representation(self, instance):
     """
     Overrides to nest the primary record and add sideloads.
     """
     ret = OrderedDict()
     base_data = self.base_serializer.__class__(
         instance,
         many=True,
         context=self.context
     ).data
     ret[pluralize(self.base_key)] = base_data
     ret.update(self.get_sideload_objects(instance))
     return ret
開發者ID:martinmaillard,項目名稱:ember-drf,代碼行數:15,代碼來源:serializers.py

示例4: get_field_info

# 需要導入模塊: from rest_framework.compat import OrderedDict [as 別名]
# 或者: from rest_framework.compat.OrderedDict import update [as 別名]
def get_field_info(model):
    """
    Given a model class, returns a `FieldInfo` instance containing metadata
    about the various field types on the model.
    """
    opts = model._meta.concrete_model._meta

    # Deal with the primary key.
    pk = opts.pk
    while pk.rel and pk.rel.parent_link:
        # If model is a child via multitable inheritance, use parent's pk.
        pk = pk.rel.to._meta.pk

    # Deal with regular fields.
    fields = OrderedDict()
    for field in [field for field in opts.fields if field.serialize and not field.rel]:
        fields[field.name] = field

    # Deal with forward relationships.
    forward_relations = OrderedDict()
    for field in [field for field in opts.fields if field.serialize and field.rel]:
        forward_relations[field.name] = RelationInfo(
            model_field=field,
            related=_resolve_model(field.rel.to),
            to_many=False,
            has_through_model=False
        )

    # Deal with forward many-to-many relationships.
    for field in [field for field in opts.many_to_many if field.serialize]:
        forward_relations[field.name] = RelationInfo(
            model_field=field,
            related=_resolve_model(field.rel.to),
            to_many=True,
            has_through_model=(
                not field.rel.through._meta.auto_created
            )
        )

    # Deal with reverse relationships.
    reverse_relations = OrderedDict()
    for relation in opts.get_all_related_objects():
        accessor_name = relation.get_accessor_name()
        reverse_relations[accessor_name] = RelationInfo(
            model_field=None,
            related=relation.model,
            to_many=relation.field.rel.multiple,
            has_through_model=False
        )

    # Deal with reverse many-to-many relationships.
    for relation in opts.get_all_related_many_to_many_objects():
        accessor_name = relation.get_accessor_name()
        reverse_relations[accessor_name] = RelationInfo(
            model_field=None,
            related=relation.model,
            to_many=True,
            has_through_model=(
                (getattr(relation.field.rel, 'through', None) is not None)
                and not relation.field.rel.through._meta.auto_created
            )
        )

    # Shortcut that merges both regular fields and the pk,
    # for simplifying regular field lookup.
    fields_and_pk = OrderedDict()
    fields_and_pk['pk'] = pk
    fields_and_pk[pk.name] = pk
    fields_and_pk.update(fields)

    # Shortcut that merges both forward and reverse relationships

    relations = OrderedDict(
        list(forward_relations.items()) +
        list(reverse_relations.items())
    )

    return FieldInfo(pk, fields, forward_relations, reverse_relations, fields_and_pk, relations)
開發者ID:AlexanderChou,項目名稱:TsinghuaCloudInt,代碼行數:80,代碼來源:model_meta.py


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