i have a category and a list of items which i was able to display according to the categories, in the following format.
CATEGORY 1
item1
item2
item3 etc
CATEGORY 1
item1
item2
item3 etc
i will want to do a pagination of the items in such a way that for each page i the category and only two (2) items is shown on a page then moves to the next one until the items in the category finishes the the next category follows suit
page 1
category 1
item1
item2
page 2
item3
item4
page 3
category 2
item1
item2
page 4
item3
item4
I already have the following
def books(request):
categories = Category.objects.all()
page_number = request.GET.get('page')
product_paginator = Paginator(categories,1)
page = product_paginator.get_page(page_number)
context = {
'page': page,
'categories': categories,
}
return render(request, 'core/index.html', context)
in my template i have something
{% for category in page.object_list %}
{{category}}
{% for product in category.cat_product.all %}
{{product.title}}
{% endfor %}
{% endfor %}