diff options
| author | Tom Christie | 2012-10-02 10:40:43 +0100 |
|---|---|---|
| committer | Tom Christie | 2012-10-02 10:40:43 +0100 |
| commit | ae8a8270042820f92b9d43597bde50d72c300513 (patch) | |
| tree | 02e6f83b483c262b4496453cd5f1eeabbcb3fe82 | |
| parent | 2284e592de6315264098e77f72b816984a50d025 (diff) | |
| download | django-rest-framework-ae8a8270042820f92b9d43597bde50d72c300513.tar.bz2 | |
Make 'results_field' attribute of BasePaginationSerializer public.
| -rw-r--r-- | docs/api-guide/pagination.md | 6 | ||||
| -rw-r--r-- | rest_framework/pagination.py | 4 |
2 files changed, 7 insertions, 3 deletions
diff --git a/docs/api-guide/pagination.md b/docs/api-guide/pagination.md index 8ef7c4cc..50be59bf 100644 --- a/docs/api-guide/pagination.md +++ b/docs/api-guide/pagination.md @@ -104,7 +104,9 @@ For more complex requirements such as serialization that differs depending on th To create a custom pagination serializer class you should override `pagination.BasePaginationSerializer` and set the fields that you want the serializer to return. -For example, to nest a pair of links labelled 'prev' and 'next' you might use something like this. +You can also override the name used for the object list field, by setting the `results_field` attribute, which defaults to `'results'`. + +For example, to nest a pair of links labelled 'prev' and 'next', and set the name for the results field to 'objects', you might use something like this. class LinksSerializer(serializers.Serializer): next = pagination.NextURLField(source='*') @@ -114,4 +116,6 @@ For example, to nest a pair of links labelled 'prev' and 'next' you might use so links = LinksSerializer(source='*') # Takes the page object as the source total_results = serializers.Field(source='paginator.count') + results_field = 'objects' + [cite]: https://docs.djangoproject.com/en/dev/topics/pagination/ diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index f8b1fd1a..131718fd 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -52,14 +52,14 @@ class BasePaginationSerializer(serializers.Serializer): to make implementing custom serializers more easy. """ _options_class = PaginationSerializerOptions - _results_field = 'results' + results_field = 'results' def __init__(self, *args, **kwargs): """ Override init to add in the object serializer field on-the-fly. """ super(BasePaginationSerializer, self).__init__(*args, **kwargs) - results_field = self._results_field + results_field = self.results_field object_serializer = self.opts.object_serializer_class self.fields[results_field] = object_serializer(source='object_list') |
