【发布时间】:2019-02-22 09:00:54
【问题描述】:
在我的 ListView 中,我想过滤当前用户从 context_data 中登录的数据:
views.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.filter()[: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
我尝试使用 query_set 进行覆盖,但它确实仅适用于链接模型
【问题讨论】:
标签: python django django-views django-class-based-views