Say I have a model that looks like:
class Action(models.Model):
user = models.ForeignKey('auth.User')
action = models.IntegerField(choices=ACTION_CHOICES)
when = models.DateTimeField()
I want to get all of the Actions for a user grouped by them being within 15 minutes of each other. Preferably in django’s ORM if possible but if there is no other way, then PostgreSQL answers wouldn’t be bad.
More clarification:
What I am looking for is along the lines of if a and b are 13 minutes apart, b and c are 10 minutes apart, a b and c would be grouped together even though a and c are 23 minutes apart.
From your example, I’m assuming each subsequent action will be within 15 minutes of the last one in a sorted list of actions: