我想使用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
答案 0 :(得分:1)
您需要覆盖get_queryset
才能访问用户对象
class ProjectsView(ListView):
#...
def get_queryset(self):
return Projects.objects.filter(user=self.request.user)