Python rest_framework.serializers.HyperlinkedIdentityField() Examples
The following are 5
code examples of rest_framework.serializers.HyperlinkedIdentityField().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
rest_framework.serializers
, or try the search function
.
Example #1
Source File: serializers.py From django-project with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #2
Source File: fields.py From normandy with Mozilla Public License 2.0 | 5 votes |
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)
Example #3
Source File: serializers.py From gro-api with GNU General Public License v2.0 | 5 votes |
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())
Example #4
Source File: renderers.py From ChRIS_ultron_backEnd with MIT License | 5 votes |
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)))]
Example #5
Source File: serializers.py From albatross with GNU Affero General Public License v3.0 | 5 votes |
def __init__(self, kind=None, **kwargs): self.view_name = "archives-distillation" self.distillation = kind serializers.HyperlinkedIdentityField.__init__( self, view_name=self.view_name, **kwargs)