【发布时间】:2020-10-13 12:37:37
【问题描述】:
我在 news_app
中有文章模型class Article(Created, HitCountMixin):
title = models.CharField(max_length=120)
author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
snippet = models.TextField(null=False)
有视图:
class AllArticlesListView(ListView):
template_name = 'news/articles_list.html'
model = Article
paginate_by = 5
def get_queryset(self):
return self.model.objects.all().order_by('-pk')
在另一个应用程序(user_app)中,我有个人资料模型:
class Profile(AbstractUser):
bio = models.TextField(blank=True, null=True, default='Brak')
有视图
class ProfileView(HitCountDetailView):
model = Profile
template_name = 'profile/profile.html'
在项目网址我有:
path("<slug:slug>", ProfileView.as_view(), name='profile'),
在 news_app url 我有:
path('all/', AllArticlesListView.as_view(), name='all_articles_list'),
如何在他的用户资料中显示所有用户文章?
class ProfileView(DetailView):
model = Profile
template_name = 'profile/profile.html'
count_hit = True
【问题讨论】:
标签: django django-views django-templates