1

I have a different design on the first page of a list, and need 8 items on the first page. On the rest I would like 9 items. I have tried to specify items on the first page, but the second page thinks the 9.th item was shown on the first page, it was not. Anyone know if it is possible to fix this?

class EntryList(ListView):

    model = Entry


    def get_paginate_by(self, queryset):

        page_kwarg = self.page_kwarg
        page = self.kwargs.get(page_kwarg) or self.request.GET.get(page_kwarg) or '1' 

        if page == '1':
            self.paginate_by = 8
        else:
            self.paginate_by = 9 #This assumes the 9.th was shown on the first page

        return self.paginate_by        
Tomas Jacobsen
  • 2,368
  • 6
  • 37
  • 81
  • Possible duplicate of [Django: paginating differently on the first page](http://stackoverflow.com/questions/1054981/django-paginating-differently-on-the-first-page) (I know that question is quite old but the approach still seems sane). – solarissmoke May 31 '16 at 09:29
  • If you create a custom paginator as the answer solarissmoke linked to suggests, you'll probably have to override [`paginator_class`](https://docs.djangoproject.com/en/1.9/ref/class-based-views/mixins-multiple-object/#django.views.generic.list.MultipleObjectMixin.paginator_class) and/or [`get_paginator`](https://docs.djangoproject.com/en/1.9/ref/class-based-views/mixins-multiple-object/#django.views.generic.list.MultipleObjectMixin.get_paginator) on your view as well. – Alasdair May 31 '16 at 10:10

0 Answers0