Add '.basename' and '.reverse_action()' to ViewSet by rpkilby · Pull Request #5648 · encode/django-rest-framework (original) (raw)
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 andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation5 Commits3 Checks0 Files changed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
Just breaking out a portion of #5605.
Description
ViewSet
s cannot effectively reverse their action URLs, as they aren't aware of the basename
they were registered to the router with. This value can be hardcoded in the view class, however this is problematic when the ViewSet
is registered with a different basename
.
- Routers now provide the
basename
with the viewset'sinitkwargs
. - Added
.reverse_action()
convenience method to viewsets.
Ryan P Kilby added 3 commits
OK. Good: I was going to look at #5605 so breaking it up is a win.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass I'd be happy to see this go in as is.
Anyone else want to review?
Bit agnostic on this - I'll leave it to you fellas.
For context, supporting #5605 would at least require the router to provide the basename
to the the viewset's initkwargs.
.revese_action()
isn't essential, but it seemed beneficial to provide a more formalized method of getting the action URLs.
...supporting #5605 ...
Which is taking on (inter alia) #2062 — Support extra actions in Browsable API — which is from Nov 2014. It would be nice to take that on. (And it seems a reasonable request right...)
OK. Lets have this.
pchiquet pushed a commit to pchiquet/django-rest-framework that referenced this pull request
Router sets 'basename' on ViewSet
Add 'ViewSet.reverse_action()' method
Test router setting initkwargs