Movatterモバイル変換


[0]ホーム

URL:


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

ResourceRelatedField with multiple related_link_url_kwarg paramaters for nested resources#1208

Marclev78 started this conversation inIdeas
Discussion options

Description of feature request

I'm not sure if this is a feature request, or a bug report, or simply my not understand the framework correctly.

It seems to be impossible to use ResourceRelatedField objects to refer to nested resources.

For example, in my model I have something like:

store/123/catalogues/222/categories

There are two ID path parameters in that URl. So in my catalogue serializer I want to do something like this:

    categories = ResourceRelatedField(        queryset=Category.objects,        many=True,        related_link_view_name='catalogue-categories-list',        related_link_url_kwargs=['store_id', catalogue_pk']    )

but I can't see any way to do that, meaning the serializer errors when it tries to use the view. Am I missing something or is it not possible to use ResourceRelatedFields for these sorts of nested resources?

I couldn't see this covered in the documentation. Is there an alternative way I should be doing it?

You must be logged in to vote

Replies: 1 comment

Comment options

Personally, I would avoid having multiple lookups per resource and keep the structure flat. Instead, rather use the JSON:APIrelationship object to link what relationship a category has to a catalog or visa-versa. This makes the API more user-friendly, as someone does not have to have two parameters to get the details of only one resource. Because of the relationship object, in my opinion, the JSON:API spec favors a flat design.

However, you could, of course, create your ownResourceRelatedField class overwritingget_links to accomplish having a lookup with several parameters.

There might be different perspective on this issue though, so converted this to a discussion for further conversations on this topic.

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Ideas
2 participants
@Marclev78@sliverc
Converted from issue

This discussion was converted from issue #1204 on March 18, 2024 17:43.


[8]ページ先頭

©2009-2025 Movatter.jp