Fix admin link for pages

This commit is contained in:
Gabriel Augendre 2020-08-17 13:17:23 +02:00
parent 644de9c72f
commit 49b1d0e9ca

View file

@ -35,6 +35,7 @@ class ArticleDetailView(generic.DetailView):
model = Article model = Article
context_object_name = "article" context_object_name = "article"
queryset = Article.with_pages.all() queryset = Article.with_pages.all()
template_name = "articles/article_detail.html"
def get_queryset(self): def get_queryset(self):
if self.request.user.is_authenticated: if self.request.user.is_authenticated:
@ -43,6 +44,8 @@ class ArticleDetailView(generic.DetailView):
def get_object(self, queryset=None): def get_object(self, queryset=None):
obj = super().get_object(queryset) obj = super().get_object(queryset)
if hasattr(obj, "page"):
obj = obj.page
if not self.request.user.is_authenticated: if not self.request.user.is_authenticated:
obj.views_count = F("views_count") + 1 obj.views_count = F("views_count") + 1
obj.save(update_fields=["views_count"]) obj.save(update_fields=["views_count"])