question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for HyperlinkedIdentityField

See original GitHub issue
Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/snippets/

Django Version: 1.10.3
Python Version: 2.7.12
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'rest_framework',
 'rest_framework_jwt',
 'rest_framework_json_api',
 'snippets.apps.SnippetsConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "/home/user/.pyenv/versions/djangorest/lib/python2.7/site-packages/django/core/handlers/exception.py" in inner
  39.             response = get_response(request)

File "/home/user/.pyenv/versions/djangorest/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
  217.                 response = self.process_exception_by_middleware(e, request)

File "/home/user/.pyenv/versions/djangorest/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
  215.                 response = response.render()

File "/home/user/.pyenv/versions/djangorest/lib/python2.7/site-packages/django/template/response.py" in render
  109.             self.content = self.rendered_content

File "/home/user/.pyenv/versions/djangorest/lib/python2.7/site-packages/rest_framework/response.py" in rendered_content
  72.         ret = renderer.render(self.data, accepted_media_type, context)

File "/home/user/.pyenv/versions/djangorest/lib/python2.7/site-packages/rest_framework/renderers.py" in render
  701.         context = self.get_context(data, accepted_media_type, renderer_context)

File "/home/user/.pyenv/versions/djangorest/lib/python2.7/site-packages/rest_framework/renderers.py" in get_context
  659.             'content': self.get_content(renderer, data, accepted_media_type, renderer_context),

File "/home/user/.pyenv/versions/djangorest/lib/python2.7/site-packages/rest_framework/renderers.py" in get_content
  409.         content = renderer.render(data, accepted_media_type, renderer_context)

File "/home/user/.pyenv/versions/djangorest/lib/python2.7/site-packages/rest_framework_json_api/renderers.py" in render
  469.                     json_resource_obj = self.build_json_resource_obj(fields, resource, resource_instance, resource_name)

File "/home/user/.pyenv/versions/djangorest/lib/python2.7/site-packages/rest_framework_json_api/renderers.py" in build_json_resource_obj
  390.         relationships = JSONRenderer.extract_relationships(fields, resource, resource_instance)

File "/home/user/.pyenv/versions/djangorest/lib/python2.7/site-packages/rest_framework_json_api/renderers.py" in extract_relationships
  91.             relation_type = utils.get_related_resource_type(field)

File "/home/user/.pyenv/versions/djangorest/lib/python2.7/site-packages/rest_framework_json_api/utils.py" in get_related_resource_type
  202.                     parent_model_relation = getattr(parent_model, relation.field_name)

Exception Type: AttributeError at /snippets/
Exception Value: type object 'Snippet' has no attribute 'highlight'

Trying to integrate djangorestframework-jsonapi into the official djangorestframework tutorial, but I keep getting errors. I followed the docs configuration instructions, and changed my serializers.py import to from rest_framework_json_api import serializers. What am I missing here? Does djangorestframework-jsonapi not support the HyperlinkedIdentityField? Or should I be using the ResourceRelatedField for relationships? Any help is greatly appreciated!

Side note: If there’s anything I would improve upon it’s the documentation. A tutorial, possibly forked from the official drf one, would be nice. Thank you for creating this project! 😃

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
sliverccommented, Oct 16, 2018

@Alig1493 I would extend the DRF tests you already have written and add a DRFEntrySerializer using HyperlinkedIdentityField for blog relation.

1reaction
sliverccommented, Aug 6, 2018

Thanks for your feedback.

Back in June when I browsing though all open tickets trying to address them I think I was bit quick with this comment. 😉 Sorry about that.

Yes indeed a tutorial would be a good idea for DJA but best trying of explain the difference between DJA and DRF. Help in this regards would be very much appreciated.

Technically DRF HyperlinkedIdentityField should also be supported but there is actually no test 😢 .

In general DRF serializers fields should technically work but as there are some specialties in JSON API specification it is recommended to use the DJA specific serializer relations. which are explained at https://django-rest-framework-json-api.readthedocs.io/en/stable/usage.html#related-fields Hope this answers your question how to move forward using DJA.

Marking this still as bug though as at least there should be a test to use HyperlinkedIdentityField and potential fix of the implementation if it can be reproduced in newest version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django REST Framework - HyperlinkedIdentityField
Django REST Framework - HyperlinkedIdentityField. ... a hyperlink that points to the current object in the serializer, you can use HyperlinkedIdentityField.
Read more >
Serializer relations - Django REST framework
HyperlinkedIdentityField. This field can be applied as an identity relationship, such as the 'url' field on a HyperlinkedModelSerializer. It can also be used ......
Read more >
How to pass argument to HyperLinkedIdentityField's view_name
I Have a HyperLinkedIDentityField and the view there is forum-api:thread_list_forum_topic but the problem is that this view requires an argument ...
Read more >
`HyperlinkedIdentityField` requires the ... - Google Groups
Hi all. I am trying to POST data on DRF and Save it,so when i am trying to access the server(http://127.0.0.1:8000/snippets/) i get...
Read more >
Unable to add links to action endpoints · Issue #885 - GitHub
It could be that the support for HyperlinkedIdentityField is not complete. Could you provide an exception stacktrace?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found