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

Get data with query params #8951

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions rest_framework/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ class ListModelMixin:
def list(self, request, *args, **kwargs):
queryset = self.filter_queryset(self.get_queryset())

try:
params = {key: value for key, value in request.query_params.items() if key in self.model._meta.get_fields()}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you mind adding unit test to verify this change?

if params is not None:
queryset = queryset.filter(**params)
except AttributeError:
pass

page = self.paginate_queryset(queryset)
if page is not None:
serializer = self.get_serializer(page, many=True)
Expand Down