我试图在ListView上显示当前登录用户发布的仅包含内容的帖子,但这里的答案:How to make generic ListView only show user's listing?无法解决我的问题,因为我的ListView使用了4个模型
视图.py
class DashboardListView(LoginRequiredMixin,ListView):
model = Links
template_name = 'dashboard/home.html'
context_object_name ='links_list'
paginate_by = 15
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['dashboard_list']= Dashboard.objects.all()[:15]
context['todo_list']= Todo.objects.all().order_by('-pk')[:15]
context['todo_complete']= Todo.objects.all().count()
context['PasswordUsername_list']= PasswordUsername.objects.all()
return context
def get_queryset(self):
return self.model.objects.filter(author=self.request.user)
我试图添加一个get\u context和一个get\u query\u set,但它只隐藏链接模型
谢谢
多亏了另一篇帖子,我才明白
在视图中.py
您必须使用“yourmodel.objects.filter(author=self.request.user)”筛选上下文 和一个查询集
相关问题 更多 >
编程相关推荐