Как добавить нумерацию страниц в Classed Based View с помощью get_context_data - PullRequest
0 голосов
/ 11 января 2019

Я хочу добавить нумерацию страниц в свой список. Я использовал paginated_by=10, но он не работает. Пожалуйста, помогите мне добавить нумерацию страниц в моем шаблоне. Какой HTML-код я должен добавить в свой шаблон

View.py

class CompanyListView(LoginRequiredMixin, generic.TemplateView):
    template_name = 'superadmin/company/company.html'

    def get_context_data(self, **kwargs):   
        context = super(CompanyListView, self).get_context_data(**kwargs)
        context['companies'] = Company.objects.exclude(company_name='Apollo').exclude(company_is_deleted = True).annotate(number_of_company_users=Count('userprofile'))
        return context

1 Ответ

0 голосов
/ 11 января 2019

Вы можете использовать ListView вместо TemplateView. Вот как.

class CompanyListView(LoginRequiredMixin, generic.ListView):
    template_name = 'superadmin/company/company.html'
    queryset = Company.objects.all()
    context_object_name = 'companies'
    paginate_by = 10

    def get_queryset(self):
        return ( 
            self.queryset.exclude(company_name='Apollo')
            .exclude(company_is_deleted =True)
            .annotate(number_of_company_users=Count('userprofile'))
        )
...