{% get_most_commented_posts as most_commented_posts %}
<ul>
{% for post in most_commented_posts %}
<li>
<a href="{{ post.get_absolute_url }}">{{ post.title }}</a>
</li>
{% endfor %}
</ul>
def get_most_commented_posts(count=5):
return Post.published.annotate(total_comments=Count('comments')).order_by('total_comments')[:count]