Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Create a top-level entry in links. #1239

germanp started this conversation in General
Discussion options

I'need to create an arbitrary link at top-level link, like the 'self' o the pagination related but I don't see an option for that. In the docs there are the ResourceRelatedField and their variants but they actually renders under 'relationships' topleve key.

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

Actually, there are three places where links can occur.

  1. There is the top-level links as in pagination. You can add additional links by either creating your custom pagination class derived of rest_framework_json_api.pagination.JsonApiPageNumberPagination and overwriting get_paginated_response or you have a custom renderer derived from rest_framework_json_api.renderes.JSONRenderer overwriting render method.
  2. There are links which are part of the resource. Currently, there is no easy way to overwrite it and you would also have to have a custom renderer overwriting build_json_resource_obj.
  3. Last, there are links which are part of the relationship field itself, which can be customized with a custom ResourceRelatedField overwriting get_links.

Hope this clarifies what is possible in terms of custom links.

You must be logged in to vote
1 reply
Comment options

Hi, thanks for the explanation. I was talking about 2nd case, links in the resource, but in my case is only for a particular endpoint. I was thinking on adding an extra field to or something like that, rewriting build_json_resource_obj seems excesive to my particular case. I currently using a normal field thats returns an url to avoid the issue by now. Maybe if I found some extra time I could think into something better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /