[Answered ]-Django limit next post and previos post on Detail view to only active

1👍

You can define two extra methods in the Post model to only retrieve active items with:

class Post(models.Model):
    # ⋮

    def get_previous_by_created_on_active(self):
        return self.get_previous_by_created_on(status=1)

    def get_next_by_created_on_active(self):
        return self.get_next_by_created_on(status=1)

This will thus only look for Posts with status=1 (so published Post objects).

Leave a comment