Answer the question
In order to leave comments, you need to log in
Pagination in Django ListView?
Good afternoon! I can’t figure out how to display the mixin from articles by date added with pagination on the page. I output in a loop, but pagination only works for the main model. There is no information on the Internet. Broke his head. Who faced?
from django.core.paginator import Paginator
from django.views.generic import ListView, DetailView
from .models import *
# Главная страница блога (статьи и реклама)
class BlogArticlesMainPage(ListView):
model = BlogArticlesHairCut
template_name = "blog/blog.html"
paginate_by = 4
def get_context_data(self, **kwargs):
context = super(BlogArticlesMainPage, self).get_context_data(**kwargs)
context['makeup'] = BlogArticlesMakeUp.objects.all() # Макияж модель
paginator = Paginator(BlogArticlesMakeUp, self.paginate_by)
page = self.request.GET.get('page')
context['nails'] = BlogArticlesNails.objects.all() # Маникюр модель
context['depil'] = BlogArticlesDepil.objects.all() # Депиляция модель
context['spa'] = BlogArticlesSpa.objects.all() # Спа услуги модель
context['tatoo'] = BlogArticlesTatoo.objects.all() # Тату услуги модель
context['block1promo'] = BlogBlock1.objects.all() # Реклама шапка
context['block2promo'] = BlogBlock2.objects.all() # Реклама центр1
context['block3promo'] = BlogBlock3.objects.all() # Реклама центр2
return context
Answer the question
In order to leave comments, you need to log in
For the main page, I would still take something like View, ListView is good if you only need to get 1 queriset, and you have a mountain of them. Well, if you look at how the Paginator class works, you will see that it accepts a querieset, not a class. And pagination works only thanks to context = super(BlogArticlesMainPage, self).get_context_data(**kwargs), which executed the code of the parent class
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question