【发布时间】:2018-12-21 02:14:34
【问题描述】:
我正在使用 Django 2.06 开发一个项目。我有多个用户,他们可以发帖,其他人可以阅读他们的帖子,这很正常。在用户个人资料页面上,用户应该看到他们自己的帖子。 这就是我卡住的地方,我如何编码查询集然后在配置文件部分用户只能看到他们自己的帖子。
代码演示
class ProfileView(ListView):
template_name = "profile.html"
queryset = QuickWord.objects.filter()
context_object_name = 'quickword'
def get_context_data(self, **Kwargs):
context = super(ProfileView, self).get_context_data(**Kwargs)
context['addproduct'] = AddProduct.objects.filter()
context['article_view'] = Article.objects.filter()
context['edit'] = Profile.objects.all().last()
return context
我知道我必须使用过滤器值,但不知道该怎么做。
谢谢
【问题讨论】:
-
您的
Article模型看起来如何?你如何存储用户写了什么帖子?
标签: python django python-3.x django-2.0