diff --git a/docs/release-notes/version-2.11.md b/docs/release-notes/version-2.11.md index 3436c9c34..112609b0e 100644 --- a/docs/release-notes/version-2.11.md +++ b/docs/release-notes/version-2.11.md @@ -6,6 +6,7 @@ * [#6393](https://github.com/netbox-community/netbox/issues/6393) - Add `description` filter for IP addresses * [#6400](https://github.com/netbox-community/netbox/issues/6400) - Add cyan color choice for plugin buttons +* [#6441](https://github.com/netbox-community/netbox/issues/6441) - Improve UI paginator to optimize page object count ### Bug Fixes diff --git a/netbox/utilities/paginator.py b/netbox/utilities/paginator.py index cdad1f230..3b9e1cb37 100644 --- a/netbox/utilities/paginator.py +++ b/netbox/utilities/paginator.py @@ -4,7 +4,9 @@ from django.core.paginator import Paginator, Page class EnhancedPaginator(Paginator): - def __init__(self, object_list, per_page, **kwargs): + def __init__(self, object_list, per_page, orphans=None, **kwargs): + + # Determine the page size try: per_page = int(per_page) if per_page < 1: @@ -12,7 +14,13 @@ class EnhancedPaginator(Paginator): except ValueError: per_page = settings.PAGINATE_COUNT - super().__init__(object_list, per_page, **kwargs) + # Set orphans count based on page size + if orphans is None and per_page <= 50: + orphans = 5 + elif orphans is None: + orphans = 10 + + super().__init__(object_list, per_page, orphans=orphans, **kwargs) def _get_page(self, *args, **kwargs): return EnhancedPage(*args, **kwargs)