django-json-api / django-rest-framework-json-api

JSON:API support for Django REST framework
https://django-rest-framework-json-api.readthedocs.org/
BSD 2-Clause "Simplified" License
1.18k stars 294 forks source link

ResourceRelatedField with multiple related_link_url_kwarg paramaters for nested resources #1204

Closed Marclev78 closed 6 months ago

Marclev78 commented 6 months ago

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?