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