Update get_object() example in permissions.md#5401
Merged
carltongibson merged 2 commits intoencode:masterfrom Sep 8, 2017
sanjuroj:patch-1
Merged
Update get_object() example in permissions.md#5401carltongibson merged 2 commits intoencode:masterfrom sanjuroj:patch-1
carltongibson merged 2 commits intoencode:masterfrom
sanjuroj:patch-1
Conversation
I'm a bit confused about the example that's provided in the 'Object level permissions' section. Other examples (e.g. Tutorial 3 - Class Based Views) provided a pk to get_object(). It doesn't seem like this example has any way of identifying a specific object. Just in case I'm correct, I've prepared this pull request. But if I'm wrong, would it be possible for you to explain the example I modified? Many Thanks...
carltongibson
requested changes
Sep 8, 2017
Collaborator
carltongibson
left a comment
There was a problem hiding this comment.
This is a valid issue. The fix isn't quite right.
Hopefully me comments are clear enough?
Thanks!
|
|
||
| For example: | ||
|
|
||
| def get_object(self): |
Collaborator
There was a problem hiding this comment.
Don't add the parameter here.
docs/api-guide/permissions.md
Outdated
| def get_object(self): | ||
| obj = get_object_or_404(self.get_queryset()) | ||
| def get_object(self, pk): | ||
| obj = get_object_or_404(self.get_queryset(), pk=pk) |
Collaborator
There was a problem hiding this comment.
The default get_object() implementation does this:
filter_kwargs = {self.lookup_field: self.kwargs[lookup_url_kwarg]}
obj = get_object_or_404(queryset, **filter_kwargs)That's a bit generic for the point being made here so I'd be happy with just:
obj = get_object_or_404(queryset, pk=self.kwargs["pk"])
carltongibson
approved these changes
Sep 8, 2017
Collaborator
carltongibson
left a comment
There was a problem hiding this comment.
I made the adjustment
Contributor
Author
|
@carltongibson Ack, sorry, didn't quite get to it fast enough. Thanks for making the adjustment. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I'm a bit confused about the example that's provided in the 'Object level permissions' section. Other examples (e.g. Tutorial 3 - Class Based Views) provided a pk to get_object(). It doesn't seem like this example has any way of identifying a specific object.
Just in case I'm correct, I've prepared this pull request. But if I'm wrong, would it be possible for you to explain the example I modified?
Many Thanks...
Note: Before submitting this pull request, please review our contributing guidelines.
Description
Please describe your pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue. When linking to an issue, please use
refs #...in the description of the pull request.