使用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),但没有一个对我有用。非常感谢您的帮助。