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
DRF integration does not work for extra viewset actions #967
Comments
Hi @estianross. You need to provide more details if we're going to be able to comment. Are you sure your extra actions are calling |
They do but I'm fairly sure I'm not using it the way it should be used if that's where the issue is, I've included a simple sample action below to show the basics of what I'm doing in these actions
|
I suggest you create an APITestCase and plug the url + query parameters you're expecting into it. You'll then be able to make assertions and insert breakpoints as needed to see where things are going wrong for you. (I'm afraid that without much more detail it's impossible to be able to advise at all.) |
I got it working by simply moving the call as follows
Thanks for the help!!! |
This does not seem to work in most of my cases. |
I think this issue should be reopened. I have the same problem and the proposed solution worked for me. |
@action(methods=['get'], detail=True, url_path='retrieve_by_card_no/(< int:CardNo> )') I want to search employee by his card no instead of employee id anyone can help me? |
I think the filter integration works correctly if you pass the query params along with your action in the URL. Below was the action that I had
When trying to call the export action from DRF browsable API, the request that was getting sent was Passing the query params along with the action will call the filterset class and hence you will get a filtered queryset in filtered_queryset variable |
Thank you so much I figured it out
…On Wed, Apr 28, 2021 at 12:32 AM Mohammed Sunasra ***@***.***> wrote:
I think the filter integration works correctly if you pass the query
params along with your action in the URL. Below was the action that I had
@action(methods=['GET'], detail=False)
def export(self, request):
queryset = self.get_queryset()
filtered_queryset = self.filter_queryset(queryset)
When trying to call the export action from DRF browsable API, the request
that was getting sent was
*/api/viewname/export/* instead it should called like
*/api/viewname/export/?query_param_1=value1&?query_param_2=value2*
Passing the query params along with the action will call the filterset
class and hence you will get a filtered queryset in filtered_queryset
variable
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#967 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMD2QQXC6FGISRWTHRAGUSTTK62Y7ANCNFSM4FP6FMMQ>
.
|
I have multiple list actions in a single viewset by making use of the @action decorator as described here and have included a FilterSet via filter_class as specified in docs here. The filters are only being applied to the default ViewSet List and Retrieve actions and not any of the custom List or Retrieve actions which is where we actually need the filters.
The text was updated successfully, but these errors were encountered: