honzakral / django-threadedcomments

django-threadedcomments is a simple yet flexible threaded commenting system for Django.
BSD 3-Clause "New" or "Revised" License
622 stars 165 forks source link

How can I count only replies on the every Comment? #101

Open tanveerahmad1517 opened 6 years ago

tanveerahmad1517 commented 6 years ago

Please I want to show the replies number on every comment that are available replies

gameot commented 5 years ago

extend model like this:

from threadedcomments.models import ThreadedComment as BaseModel
class ThreadedCommentExt(BaseModel):
    class Meta:
        verbose_name = _("Comment")
        verbose_name_plural = _("Comments")
        proxy = True
        managed = False

    def get_replies_count(self):
        count = 0
        comments = ThreadedCommentExt.objects.filter(parent=self)
        for item in comments:
            count += item.get_replies_count() + 1
        return count