-
Notifications
You must be signed in to change notification settings - Fork 299
Added related fields filtering #504
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
Conversation
417e7f4
to
747982a
Compare
For this PR it just allows to filter related querysets.
What do you think about it ? If it looks good for you I can add some tests and update the docs.
Thanks
@Anton-Shutik Actually this might be better than returning an error as you do in #505 if the goal is to reduce the related queryset to those allowed to be returned. Basically the related_filter_backends
is a permission filter that only returns items that are permitted to be returned.
The goal I think is to silently not return related data when not permitted (make it invisible) rather than have the request fail. Does that make sense @lcary?
@n2ygk related_filter_backends
is just for filtering. It should not check any permissions or something. It is made same way like DRF does. Filters and permissions are separate things. Let's do not mix it. If you want to hide some items from current customer - add a IsNotHiddenItemFilter
and it will just filter out all items that the customer shouldn't see. It you want to check permissions for a given endpoint (or resource) add a IsStuffUser
(for example) and that will return response only for stuff users. That's it.
Permissions check is a permission check. It should not do any filtering at all. And filtering is just filtering it should not check anything. That's why I've made 2 separate PRs for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #496 (comment)
Closing this for now as the discussion in #496 continues how the issue can be solved.
Fixes #
This simple PR adds fitlering for related querysets. Let's say we have an url like /api/order/1/items/ and I want for filter the items by
available=true
. There is no way to do it now.With this PR we can do this by adding filter backend to the OrderviewSet:
That's it.
Filtering work exactly same way as standard DRF's filtering.
Description of the Change
Checklist
CHANGELOG.md
AUTHORS