views:

41

answers:

1

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.

A: 

It turns out this method actually works, it was a bug elsewhere that was causing problems with output.

sotangochips