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

PaginationSerializer hardcoded to use ListSerializer #2327

Closed
brianmay opened this issue Dec 20, 2014 · 3 comments · Fixed by #2331
Closed

PaginationSerializer hardcoded to use ListSerializer #2327

brianmay opened this issue Dec 20, 2014 · 3 comments · Fixed by #2331
Labels
Milestone

Comments

@brianmay
Copy link

brianmay commented Dec 20, 2014

To me it feels like it should use Meta.list_serializer_class of the object serializer if it is defined instead.

diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py
index fb45128..94c2f2d 100644
--- a/rest_framework/pagination.py
+++ b/rest_framework/pagination.py
@@ -68,7 +68,12 @@ class BasePaginationSerializer(serializers.Serializer):
         except AttributeError:
             object_serializer = DefaultObjectSerializer

-        self.fields[results_field] = serializers.ListSerializer(
+        try:
+            list_serializer = object_serializer.Meta.list_serializer_class
+        except AttributeError:
+            list_serializer = serializers.ListSerializer
+
+        self.fields[results_field] = list_serializer(
             child=object_serializer(),
             source='object_list'
         )
@tomchristie
Copy link
Member

tomchristie commented Dec 20, 2014

Improvements to the pagination API will come in 3.1. Tracking against #1169

@tomchristie
Copy link
Member

tomchristie commented Dec 20, 2014

Actually this could still be valid in the meantime.

@brianmay
Copy link
Author

brianmay commented Dec 20, 2014

It seems to solve my immediate problem anyway.

@tomchristie tomchristie reopened this Dec 20, 2014
@tomchristie tomchristie added this to the 3.0.3 Release milestone Dec 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants