Beispiel #1
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

        paginator = Paginator(self.zhaopin_list, 10)
        page = self.request.GET.get('page', 1)
        page_range = paginator.page_range
        zhaopin_list = paginator.page(page)
        list_num = paginator.count

        start, end = custom_paginator(int(page), len(page_range), 10)
        page_range = range(start, end + 1)
        # 获取所有的工作地和分类
        category_list = Category.objects.filter(~Q(name=''))
        workLocation_list = WorkLocation.objects.all()
        workLocation_list1 = workLocation_list[:9]
        workLocation_list2 = workLocation_list[9:]

        context.update({
            'list_num': list_num,
            'page_range': page_range,
            'zhaopin_list': zhaopin_list,
            'workLocation_id': self.workLocation_id,
            'category_id': self.category_id,
            'keywords': self.keywords,
            'category_list': category_list,
            'workLocation_list1': workLocation_list1,
            'workLocation_list2': workLocation_list2
        })
        return context
Beispiel #2
0
 def get_context_data(self, **kwargs):
     # 调用父类的get_context_data方法
     context = super().get_context_data(**kwargs)
     # 获取分页相关的变量
     page = context.get('page_obj')
     paginator = context.get('paginator')
     # 调用我们自定义的分页方法
     start, end = custom_paginator(page.number, paginator.num_pages, 4)
     # 将我们的start 和 end 写入context中
     context.update({'page_range': range(start, end + 1)})
     # 返回context
     return context
Beispiel #3
0
 def get_context_data(self, **kwargs):
     # 先调用父类方法,获取默认的context
     context = super().get_context_data()
     # ListView传递了和分页有关的模板变量
     # paginator是Paginator的实例,is_paginated是否已分页
     # page_obj 当前请求页面的分页对象
     # object_list 请求页面的对象列表.和post_list等价,注意是请求页
     pagiator = context.get('paginator')
     page = context.get('page_obj')
     start, end = custom_paginator(page.number, pagiator.num_pages, 4)
     context.update({'page_range': range(start, end + 1)})
     return context