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


Python api_settings.URL_FIELD_NAME属性代码示例

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


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

示例1: build_json_resource_obj

# 需要导入模块: from rest_framework.settings import api_settings [as 别名]
# 或者: from rest_framework.settings.api_settings import URL_FIELD_NAME [as 别名]
def build_json_resource_obj(cls, fields, resource, resource_instance, resource_name,
                                force_type_resolution=False):
        """
        Builds the resource object (type, id, attributes) and extracts relationships.
        """
        # Determine type from the instance if the underlying model is polymorphic
        if force_type_resolution:
            resource_name = utils.get_resource_type_from_instance(resource_instance)
        resource_data = [
            ('type', resource_name),
            ('id', encoding.force_str(resource_instance.pk) if resource_instance else None),
            ('attributes', cls.extract_attributes(fields, resource)),
        ]
        relationships = cls.extract_relationships(fields, resource, resource_instance)
        if relationships:
            resource_data.append(('relationships', relationships))
        # Add 'self' link if field is present and valid
        if api_settings.URL_FIELD_NAME in resource and \
                isinstance(fields[api_settings.URL_FIELD_NAME], relations.RelatedField):
            resource_data.append(('links', {'self': resource[api_settings.URL_FIELD_NAME]}))
        return OrderedDict(resource_data) 
开发者ID:django-json-api,项目名称:django-rest-framework-json-api,代码行数:23,代码来源:renderers.py

示例2: get_serializer_info

# 需要导入模块: from rest_framework.settings import api_settings [as 别名]
# 或者: from rest_framework.settings.api_settings import URL_FIELD_NAME [as 别名]
def get_serializer_info(self, serializer):
        """
        Given an instance of a serializer, return a dictionary of metadata
        about its fields.
        """
        if hasattr(serializer, 'child'):
            # If this is a `ListSerializer` then we want to examine the
            # underlying child serializer instance instead.
            serializer = serializer.child

        # Remove the URL field if present
        serializer.fields.pop(api_settings.URL_FIELD_NAME, None)

        return OrderedDict([
            (format_value(field_name), self.get_field_info(field))
            for field_name, field in serializer.fields.items()
        ]) 
开发者ID:django-json-api,项目名称:django-rest-framework-json-api,代码行数:19,代码来源:metadata.py

示例3: get_default_field_names

# 需要导入模块: from rest_framework.settings import api_settings [as 别名]
# 或者: from rest_framework.settings.api_settings import URL_FIELD_NAME [as 别名]
def get_default_field_names(self, declared_fields, model_info):
        return (
            [api_settings.URL_FIELD_NAME] +
            list(declared_fields.keys()) +
            list(model_info.fields.keys()) +
            list(model_info.forward_relations.keys()) +
            list(model_info.reverse_relations.keys())
        ) 
开发者ID:OpenAgricultureFoundation,项目名称:gro-api,代码行数:10,代码来源:serializers.py

示例4: build_field

# 需要导入模块: from rest_framework.settings import api_settings [as 别名]
# 或者: from rest_framework.settings.api_settings import URL_FIELD_NAME [as 别名]
def build_field(self, field_name, info, model_class, nested_depth):
        if field_name in info.fields_and_pk:
            model_field = info.fields_and_pk[field_name]
            return self.build_standard_field(field_name, model_field)
        elif field_name in info.relations:
            relation_info = info.relations[field_name]
            if not nested_depth:
                field_class, field_kwargs = self.build_relational_field(
                    field_name, relation_info
                )
            else:
                field_class, field_kwargs = self.build_nested_field(
                    field_name, relation_info, nested_depth
                )
            # TODO: Make sure this actually does something
            # Don't allow writes to relations resulting from foreign keys
            # pointing to this class
            if relation_info.model_field is None:
                field_kwargs['read_only'] = True
                if 'queryset' in field_kwargs:
                    field_kwargs.pop('queryset')
            return field_class, field_kwargs
        elif hasattr(model_class, field_name):
            return self.build_property_field(field_name, model_class)
        elif field_name == api_settings.URL_FIELD_NAME:
            return self.build_url_field(field_name, model_class)
        return self.build_unknown_field(field_name, model_class) 
开发者ID:OpenAgricultureFoundation,项目名称:gro-api,代码行数:29,代码来源:serializers.py

示例5: get_success_headers

# 需要导入模块: from rest_framework.settings import api_settings [as 别名]
# 或者: from rest_framework.settings.api_settings import URL_FIELD_NAME [as 别名]
def get_success_headers(self, data):
        try:
            return {'Location': str(data[api_settings.URL_FIELD_NAME])}
        except (TypeError, KeyError):
            return {} 
开发者ID:BeanWei,项目名称:Dailyfresh-B2C,代码行数:7,代码来源:mixins.py

示例6: handle_nested_serializer

# 需要导入模块: from rest_framework.settings import api_settings [as 别名]
# 或者: from rest_framework.settings.api_settings import URL_FIELD_NAME [as 别名]
def handle_nested_serializer(self, resource, field, field_name, request):
        serializer_field = get_related_field(field)

        if hasattr(serializer_field, "opts"):
            model = serializer_field.opts.model
        else:
            model = serializer_field.Meta.model

        resource_type = self.model_to_resource_type(model)

        linked_ids = self.dict_class()
        links = self.dict_class()
        linked = self.dict_class()
        linked[resource_type] = []

        if is_related_many(field):
            items = resource[field_name]
        else:
            items = [resource[field_name]]

        obj_ids = []

        resource.serializer = serializer_field

        for item in items:
            converted = self.convert_resource(item, resource, request)
            linked_obj = converted["data"]
            linked_ids = converted.pop("linked_ids", {})

            if linked_ids:
                linked_obj["links"] = linked_ids

            obj_ids.append(converted["data"]["id"])

            field_links = self.prepend_links_with_name(
                converted.get("links", {}), resource_type)

            field_links[field_name] = {
                "type": resource_type,
            }

            if "href" in converted["data"]:
                url_field_name = api_settings.URL_FIELD_NAME
                url_field = serializer_field.fields[url_field_name]

                field_links[field_name]["href"] = self.url_to_template(
                    url_field.view_name, request, field_name,
                )

            links.update(field_links)

            linked[resource_type].append(linked_obj)

        if is_related_many(field):
            linked_ids[field_name] = obj_ids
        else:
            linked_ids[field_name] = obj_ids[0]

        return {"linked_ids": linked_ids, "links": links, "linked": linked} 
开发者ID:kevin-brown,项目名称:drf-json-api,代码行数:61,代码来源:renderers.py


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