Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support specifying lookup name for hyperlinked fields to related_views #919

Closed
SafaAlfulaij opened this issue Apr 16, 2021 · 2 comments
Closed

Comments

@SafaAlfulaij
Copy link
Contributor

Refer to: #904

There is no way currently to pass a custom lookup name of related_views to hyperlinked fields.
The below field should link to /entries/123/comments instead of /entries/123/comments_hyperlinked.

    comments_hyperlinked = relations.HyperlinkedRelatedField(
        related_link_view_name="entry-related",
        related_link_url_kwarg="entry_pk",
        self_link_view_name="entry-relationships",
        many=True,
        read_only=True,
        source="comments",
    )
@sliverc
Copy link
Member

sliverc commented Apr 20, 2021

This is in the example app like this but I wonder whether it makes any sense at all to define a related field to the same relationship twice on the same serializer: one hyperlinked and one as resource.

I haven't tested this but if the hyperlink is defined like the below it should actually work right?

    comments = relations.HyperlinkedRelatedField(
        related_link_view_name="entry-related",
        related_link_url_kwarg="entry_pk",
        self_link_view_name="entry-relationships",
        many=True,
        read_only=True,
    )

If so my question would be what the use case is for referencing the same relation once hyperlinked and once a resource is?

@sliverc
Copy link
Member

sliverc commented Sep 23, 2021

I thought about this issue again and actually the url the hyperlinked related field produces is correct, the issue is though that the test EntrySerializer does not either add a included_serializers or related_serializers for the field comments_hyperlinked. So this is a issue in the configuration of the example app. As of #468 we are currently cleaning up all the tests and then the example app so this will be addressed there too. Therefore closing this issue.

If I missed anything and this is actually a DJA and not a test issue please feel free to comment.

@sliverc sliverc closed this as completed Sep 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants