I have some problem with understanding django pagination in Wagtail cms. I read this topic Pagination in Wagtail
So it is not works well for me. In my templates for get products i use this code
{% for product in page.get_children.specific %}
<div class="col-12 col-sm-6 col-lg-4">
<div class="single-best-receipe-area mb-30">
{% image product.product_photo width-400 %}
<div class="receipe-content">
<a href="{% pageurl product %}">
<h5>{{ product.title }}</h5>
</a>
</div>
</div>
</div>
{% endfor %}
and then:
<ul class="pagination">
{% if product.has_previous %}
<li><a href="?page={{ product.previous_page_number }}"><i class="fa fa-angle-left"></i></a></li>
{% endif %}
{% for page_num in product.paginator.page_range %}
<li {% if page_num == product.number %}class="active" {% endif %}><a
href="?page={{ page_num }}">{{ page_num }}</a></li>
{% endfor %}
{% if product.has_next %}
<li><a href="?page={{ product.next_page_number }}"><i class="fa fa-angle-right"></i></a></li>
{% endif %}
</ul>
in my models.py i use this:
class ProductsPage(Page):
body = models.CharField(max_length=255, blank=True, help_text = 'Описание страницы')
product_image = models.ForeignKey(
"wagtailimages.Image",
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+',
help_text='Фотография Категории'
)
content_panels = Page.content_panels + [
FieldPanel('body', classname="full"),
ImageChooserPanel('product_image'),
]
def get_context(self, request):
context = super(ProductsPage, self).get_context(request)
all_product = OneProduct.objects.live()
paginator = Paginator(all_product, 1) # Show 3 product per page
page = request.GET.get('page')
try:
product = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
product = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
product = paginator.page(paginator.num_pages)
# make the variable 'product' available on the template
context['product'] = product
return context
finally i saw pagination but there are all products on every page i understand that problem is in this part of template
{% for product in page.get_children.specific %}
because i take all products.But how can i solve this?