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


Python serializers.HyperlinkedIdentityField方法代码示例

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


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

示例1: get_related_object_url

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import HyperlinkedIdentityField [as 别名]
def get_related_object_url(self, obj, field):
        try:
            obj = getattr(obj, field)
            if callable(obj):
              obj = obj()
            default_view_name = '%(model_name)s-detail'

            format_kwargs = {
                'app_label': obj._meta.app_label,
                'model_name': obj._meta.object_name.lower()
            }
            view_name = default_view_name % format_kwargs

            s = serializers.HyperlinkedIdentityField(source=obj, view_name=view_name)
            s.initialize(self, None)
            return s.field_to_native(obj, None)
        except Exception as e:
            print('WARN', e)
            return None 
开发者ID:peragro,项目名称:django-project,代码行数:21,代码来源:serializers.py

示例2: to_representation

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import HyperlinkedIdentityField [as 别名]
def to_representation(self, value):
        # HyperlinkedIdentityField demands a request when creating
        # urls, but one is not always available. Instead of erroring
        # out hard, fake it.
        if "request" not in self.context:
            self.context["request"] = None
        return super().to_representation(value) 
开发者ID:mozilla,项目名称:normandy,代码行数:9,代码来源:fields.py

示例3: get_resources

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import HyperlinkedIdentityField [as 别名]
def get_resources(self, obj):
        child = serializers.HyperlinkedIdentityField(
            view_name=self.resources_view_name
        )
        field = serializers.ListField(child=child)
        field.parent = self
        return field.to_representation(obj.resources.all()) 
开发者ID:OpenAgricultureFoundation,项目名称:gro-api,代码行数:9,代码来源:serializers.py

示例4: _get_related_fields

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import HyperlinkedIdentityField [as 别名]
def _get_related_fields(self, fields, id_field):
        return [k for (k, v) in fields
                if k != id_field
                and (isinstance(v, HyperlinkedRelatedField)
                or isinstance(v, HyperlinkedIdentityField)   
                or isinstance(v, ItemLinkField)
                or (isinstance(v, ManyRelatedField)
                    and isinstance(v.child_relation, HyperlinkedRelatedField)))] 
开发者ID:FNNDSC,项目名称:ChRIS_ultron_backEnd,代码行数:10,代码来源:renderers.py

示例5: __init__

# 需要导入模块: from rest_framework import serializers [as 别名]
# 或者: from rest_framework.serializers import HyperlinkedIdentityField [as 别名]
def __init__(self, kind=None, **kwargs):
        self.view_name = "archives-distillation"
        self.distillation = kind
        serializers.HyperlinkedIdentityField.__init__(
            self, view_name=self.view_name, **kwargs) 
开发者ID:danielquinn,项目名称:albatross,代码行数:7,代码来源:serializers.py


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