我想將上一篇文章和下一篇文章功能添加到博客頁面,但它工作正常,但在將活動的被動功能添加到博客時不起作用。獲取django下一篇文章和以前的帖子?
這裏是我的view.py
model = Blog
queryset = Blog.objects.filter(is_active__exact=True)
template_name = 'site/Blog/post.html'
pk_url_kwarg = "id"
slug_url_kwarg = 'slug'
slug_field = 'slug_tr'
query_pk_and_slug = True
def get_context_data(self, **kwargs):
context = super(BlogDetailView, self).get_context_data(**kwargs)
recent_posts = Blog.objects.all().order_by('-created_at')[:3]
comments = BlogComment.objects.filter(target_blog__exact=self.object)
previous_post = Blog.objects.filter(is_active=True).filter(created_at__lt=self.object.created_at).order_by('-created_at')[:1]
next_post_c = Blog.objects.filter(is_active=True).filter(created_at__gt=self.object.created_at).order_by('-created_at')[:1]
我怎樣才能解決這個問題?
「不工作」是一個問題的完全無用的描述,我開始看你(格式錯誤)的代碼片段,以半猜你的意思是「加入主動被動特徵「。 –