(self)
Update the counts for the parent and root
Update the counts for the parent and root
Update the counts for the parent and root
def update_parent_counts(self):
        """
        Update the counts for the parent and root
        """

        descendants = Post.objects.filter(root=self.root).exclude(Q(pk=self.root.pk) | Q(status=Post.DELETED)
                                                                  | Q(spam=Post.SPAM))
        answer_count = descendants.filter(type=Post.ANSWER).count()
        comment_count = descendants.filter(type=Post.COMMENT).count()
        reply_count = descendants.count()
        # Update the root reply, answer, and comment counts.
        Post.objects.filter(pk=self.root.pk).update(reply_count=reply_count, answer_count=answer_count,
                                                    comment_count=comment_count)

        children = Post.objects.filter(parent=self.parent).exclude(pk=self.parent.pk)
        com_count = children.filter(type=Post.COMMENT).count()

        # Update parent reply, answer, and comment counts.
        Post.objects.filter(pk=self.parent.pk, is_toplevel=False).update(comment_count=com_count, answer_count=0,
                                                                         reply_count=children.count())
def update_parent_counts ( self ) : descendants = Post . objects . filter ( root = self . root ) . exclude ( Q ( pk = self . root . pk ) | Q ( status = Post . DELETED ) | Q ( spam = Post . SPAM ) ) answer_count = descendants . filter ( type = Post . ANSWER ) . count ( ) comment_count = descendants . filter ( type = Post . COMMENT ) . count ( ) reply_count = descendants . count ( ) # Update the root reply, answer, and comment counts. Post . objects . filter ( pk = self . root . pk ) . update ( reply_count = reply_count , answer_count = answer_count , comment_count = comment_count ) children = Post . objects . filter ( parent = self . parent ) . exclude ( pk = self . parent . pk ) com_count = children . filter ( type = Post . COMMENT ) . count ( ) # Update parent reply, answer, and comment counts. Post . objects . filter ( pk = self . parent . pk , is_toplevel = False ) . update ( comment_count = com_count , answer_count = 0 , reply_count = children . count ( ) )