Say I have a list of photos ordered by creation date, as follows:
class Photo(models.Model):
title = models.Char()
image = models.Image()
created = models.DateTimeField(auto_now_add=True)
class Meta:
ordering = ('-created',)
I have an arbitrary Photo object photo_x. Is there an easy way to find the previous and next photos by position in the queryset? Also, I would like to wrap around if I am at the beginning/end and have it not fail if the are only 1 or 2 photos.