Вы можете просто запросить как:
def post_detail(request,slug):
post=get_object_or_404(Post,slug=slug)
comments=Comment.objects.filter(post=post,reply=None,statusc=2).order_by('-date')
comment_count=len(comments)
related_items = Post.objects.filter(
<b>tag__post=post</b>
).order_by('-created_date').distinct()[:3]
# ...
Или, если вы хотите исключить текущее сообщение:
def post_detail(request,slug):
post=get_object_or_404(Post,slug=slug)
comments=Comment.objects.filter(post=post,reply=None,statusc=2).order_by('-date')
comment_count=len(comments)
related_items = Post.objects<b>.exclude(pk=post.pk)</b>.filter(
tag__post=pos
).order_by('-created_date').distinct()[:3]
# ...
Также лучше выполнить len(..)
для comments
, поскольку это приведет к созданию запроса для получения комментариев, тогда как при использовании двух отдельных запросов попадет в базу данных дважды.