Imagine for a moment that I have a system that allows users to take notes. I've got a User model and a Note model:
class User(models.Model):
name = models.TextField()
class Note(models.Model):
contents = models.TextField()
user = models.ForeignKey(User)
created_at = models.DateTimeField(auto_now_add=True)
I'd like to get a rank ordered number of notes in the last 24 hours. Currently I'm doing this:
User.objects.filter(note__created_at__gt=datetime.now()-timedelta(days=2)).annotate(note_count=Count('note')).order_by('-note_count')
This gives the same result whether I do timedelta(days=2) or timedelta(seconds=1)
Any help would be appreciated.