-
Notifications
You must be signed in to change notification settings - Fork 300
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 1 reply
-
Actually, there are three places where links can occur.
- 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.JsonApiPageNumberPaginationand overwritingget_paginated_responseor you have a custom renderer derived fromrest_framework_json_api.renderes.JSONRendereroverwriting render method. - 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. - Last, there are links which are part of the relationship field itself, which can be customized with a custom
ResourceRelatedFieldoverwritingget_links.
Hope this clarifies what is possible in terms of custom links.
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.