0

please how can i determine number of objects/page show(not number of pages) in Django when using ListView Pagination. that's my code in Views.py :

from django.shortcuts import render
from django.views.generic import ListView, DetailView
from .models import Post

class PostList(ListView):
    model=Post
    context_object_name='all_post'
    ordering=['-created_at']

thank you!

  • 1
    Does this answer your question? [How do I use pagination with Django class based generic ListViews?](https://stackoverflow.com/questions/5907575/how-do-i-use-pagination-with-django-class-based-generic-listviews) – Abdul Aziz Barkat Sep 21 '21 at 12:21
  • See [Paginating a ListView - Django docs](https://docs.djangoproject.com/en/3.2/topics/pagination/#paginating-a-listview) – Abdul Aziz Barkat Sep 21 '21 at 12:23

1 Answers1

0

Just add paginate_by = <number of items in a page> to your view.

For example:

from django.shortcuts import render
from django.views.generic import ListView, DetailView
from .models import Post

class PostList(ListView):
    model=Post
    context_object_name='all_post'
    ordering=['-created_at']
    paginate_by = 10 # 10 items in a page
black
  • 799
  • 1
  • 9
  • 23