基于django类的多重分页视图

时间:2014-06-20 21:59:07

标签: python django pagination django-views django-class-based-views

以下代码对查询集进行分页,但如何对上下文进行分页[' guser1']

class AuthorList(ListView):
    template_name = 'authorList.html'
    paginate_by = 10
    queryset = Author.objects.order_by('date')

def get_context_data(self, **kwargs):
    context = super(AuthorList, self).get_context_data(**kwargs)
    if int(self.kwargs['user_id']) != self.request.user.id:
        raise PermissionDenied
    if self.request.user.username == 'guest':
        raise PermissionDenied
    context['guser1'] = Author.objects.order_by('date').filter(
                 real_date__lte=datetime.now()).filter(
                 created_by=int(self.kwargs['user_id']))

    context['guser'] = User.objects.filter(pk=int(self.kwargs['user_id']))
    return context

0 个答案:

没有答案