如何使用通用ListView

时间:2014-01-15 22:03:21

标签: python django django-views

我想使用ListView显示每页10个对象的列表。这些对象由发出请求的用户进行过滤。

class ProjectsView(ListView):
  queryset = Projects.objects.filter(user=request.user) # How/Where can I pass request ?
  template_name = 'projects.html'
  model = ? # since queryset is defined, should I use model too? 
  paginate_by = 10 # what variables do I set to display 10 objects?

TIA

1 个答案:

答案 0 :(得分:1)

您需要覆盖get_queryset才能访问用户对象

class ProjectsView(ListView):
    #...
    def get_queryset(self):
       return Projects.objects.filter(user=self.request.user)