Make default page size configurable

This commit is contained in:
Johannes Schriewer 2025-01-06 01:01:37 +01:00
parent 417606c214
commit 48e963bef1
3 changed files with 9 additions and 2 deletions

View file

@ -2,6 +2,7 @@ from django.core.paginator import Paginator
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.views.generic import ListView, DetailView
from django.conf import settings
from inventory.models import Distributor, Item
@ -13,7 +14,8 @@ class DistributorView(DetailView):
def get_context_data(self, *args, object_list=None, **kwargs):
result = super().get_context_data(*args, object_list=object_list, **kwargs)
p = self.request.GET.get("item_page", 1)
paginator = Paginator(Item.objects.filter(distributor=self.get_object()).select_related('container', 'manufacturer').order_by('name'), 50)
items = Item.objects.filter(distributor=self.get_object()).select_related('container', 'manufacturer')
paginator = Paginator(items, getattr(settings, "PAGE_SIZE", 10))
result.update({
"items": paginator.get_page(p)
})

View file

@ -2,6 +2,7 @@ from django.core.paginator import Paginator
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.views.generic import ListView, DetailView
from django.conf import settings
from inventory.models import Manufacturer, Item
@ -14,7 +15,8 @@ class ManufacturerView(DetailView):
def get_context_data(self, *args, object_list=None, **kwargs):
result = super().get_context_data(*args, object_list=object_list, **kwargs)
p = self.request.GET.get("item_page", 1)
paginator = Paginator(Item.objects.filter(manufacturer=self.get_object()).select_related('container', 'distributor').order_by('name'), 50)
items = Item.objects.filter(manufacturer=self.get_object()).select_related('container', 'distributor')
paginator = Paginator(items, getattr(settings, "PAGE_SIZE", 10))
result.update({
"items": paginator.get_page(p)
})

View file

@ -139,3 +139,6 @@ STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
SERVE_MEDIA_FILES = DEBUG
# Default page size for paginated content
PAGE_SIZE = 25