(self, u=None, **kwargs)
return query
Returns posts that are not closed or marked as spam.
Returns posts that are not closed or marked as spam.
Returns posts that are not closed or marked as spam .
def valid_posts(self, u=None, **kwargs):
        """
        Returns posts that are not closed or marked as spam.
        """
        query = super().get_queryset().filter(**kwargs)

        # Exclude posts with no root or parents
        query = query.exclude(Q(root=None) | Q(parent=None))

        # Moderators get to see all posts by default.
        if u and u.is_authenticated and u.profile.is_moderator:
            return query

        # Filter for open posts.
        query = query.filter(status=Post.OPEN, root__status=Post.OPEN)

        # Mark every spam post as 'closed'
        # This doubles the query time.
        query = query.exclude(models.Q(spam=Post.SPAM) | models.Q(root__spam=Post.SPAM))

        return query
def valid_posts ( self , u = None , * * kwargs ) : query = super ( ) . get_queryset ( ) . filter ( * * kwargs ) # Exclude posts with no root or parents query = query . exclude ( Q ( root = None ) | Q ( parent = None ) ) # Moderators get to see all posts by default. if u and u . is_authenticated and u . profile . is_moderator : return query # Filter for open posts. query = query . filter ( status = Post . OPEN , root__status = Post . OPEN ) # Mark every spam post as 'closed' # This doubles the query time. query = query . exclude ( models . Q ( spam = Post . SPAM ) | models . Q ( root__spam = Post . SPAM ) ) return query