【发布时间】:2015-05-09 19:37:47
【问题描述】:
使用django-taggit,我想获取与当前帖子具有相同标签的相关帖子。以下是观点:
from taggit.managers import TaggableManager, TaggedItem
from taggit.models import Tag
def post(request, post_slug):
post = Article.objects.get(slug = post_slug)
comments = Comment.objects.filter(post=post)
#tag = get_object_or_404(Tag, id= post.id)
#related = Article.objects.filter(tags= post.tags.similar_objects())
print "RELATED \n"
#print related
d = dict(post=post, comments=comments, form=CommentForm(),
user=request.user)
d.update(csrf(request))
return render_to_response("article/post.html", d)
我查看了文档和不同的答案(例如 this),但没有一个对我有用。非常感谢您的帮助。
【问题讨论】:
-
post.tags.similar_objects()本身不提供包含您想要的结果的列表吗? (见documentation here) -
@LaundroMat 是的,确实如此!请回答,我会接受。
标签: django django-taggit