[Fixed]-How to continue the object in django get_next/previous_by_date_created and published?

1👍

An implementation which will work is:

def get_previous_by_created_and_published(self):
    prev = Post.objects.filter(created__lte=self.created,
                               published=True
                               ).order_by('-created').first()
    return prev

Though I’m assuming here that if there are multiple published posts created before this then you’ll only want the most recent, as the name of your method suggests.

get_next_by_created_and_published will work in a similar manner, though with __gte and the ordering flipped.

Leave a comment