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 Post
s with status=1
(so published Post
objects).
Source:stackexchange.com