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

Pagination classes issue #98

Closed
CorneiZeR opened this issue Oct 14, 2024 · 1 comment · Fixed by #99
Closed

Pagination classes issue #98

CorneiZeR opened this issue Oct 14, 2024 · 1 comment · Fixed by #99

Comments

@CorneiZeR
Copy link
Contributor

I spent quite a lot of time to figure out why this library didn't work for me, here are my settings:

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.IsAuthenticated',
    ],

    'DEFAULT_AUTHENTICATION_CLASSES': [
        'user.authentication.CustomAuthentication',
        'rest_framework.authentication.SessionAuthentication'
    ],

    # Pagination
    'DEFAULT_PAGINATION_CLASS': 'common.pagination.CustomPagination',
    'PAGE_SIZE': 100,

    # For swagger
    'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',

    # For excel
    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework.renderers.JSONRenderer',
        'rest_framework.renderers.BrowsableAPIRenderer',
        'drf_excel.renderers.XLSXRenderer',
    ),
}

In the end, I found out that everything didn’t work specifically because I had custom pagination in the drf settings. To fix everything, I needed to add: pagination_class = None. It would be convenient for new users to indicate in the documentation:

from rest_framework.viewsets import ReadOnlyModelViewSet
from drf_excel.mixins import XLSXFileMixin
from drf_excel.renderers import XLSXRenderer

from .models import MyExampleModel
from .serializers import MyExampleSerializer

class MyExampleViewSet(XLSXFileMixin, ReadOnlyModelViewSet):
    queryset = MyExampleModel.objects.all()
    serializer_class = MyExampleSerializer
    renderer_classes = (XLSXRenderer,)
    filename = 'my_export.xlsx'
    pagination_class = None  # If you have a custom pagination class set in your settings
@CorneiZeR
Copy link
Contributor Author

PR for fixing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant