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