About Related Posts
To get posts similar to the current one based on the matching tags, you can use such a queryset:
tag_slugs = post.tags.values_list("slug", flat=True)
related_posts = Post.objects.exclude(slug=post.slug).annotate(
matching_tags_count=models.Count(
"tags",
filter=models.Q(tags__slug__in=tag_slugs),
)
).order_by("-matching_tags_count")
Tips and Tricks Programming Django 5.x Django 4.2 Django 3.2
Also by me
Django Paddle Subscriptions app
For Django-based SaaS projects.
Django App for You
Django GDPR Cookie Consent app
For Django websites that use cookies.
Django App for You