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

feat(generic): allow to disable pagination in table class #1454

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 6 additions & 5 deletions apis_core/generic/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from collections import namedtuple
from copy import copy
from typing import Optional

from dal import autocomplete
from django import forms, http
Expand Down Expand Up @@ -204,12 +203,14 @@ def get_queryset(self):
queryset = first_member_match(queryset_methods) or (lambda x: x)
return self.filter_queryset(queryset(self.model.objects.all()))

def get_paginate_by(self, table_data) -> Optional[int]:
def get_table_pagination(self, table):
"""
Override `get_paginate_by` from the tables2 TableMixinBase,
so we can set the paginate_by value as attribute of the table.
Override `get_table_pagination` from the tables2 TableMixinBase,
so we can set the paginate_by and the table_pagination value as attribute of the table.
"""
return getattr(self.get_table_class(), "paginate_by", None)
self.paginate_by = getattr(table, "paginate_by", None)
self.table_pagination = getattr(table, "table_pagination", None)
return super().get_table_pagination(table)


class Detail(GenericModelMixin, PermissionRequiredMixin, DetailView):
Expand Down
5 changes: 3 additions & 2 deletions docs/source/customization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ useful `django table columns
that you might want to use.

Your table can also contain a ``paginate_by`` attribute, which is then used
by the list view to determines the number of items per page, or ``None`` for no
pagination (which is the default).
by the list view to determines the number of items per page. When this is not
set, the page size defaults to ``25``. To disable pagination altogether, use
``table_pagination = False``.

The base queryset that is used in the listview, which is then filtered using
the django-filters filter, is ``model.objects.all()`` - but you can override
Expand Down