How to add a date filter to an Aggregation query in Django

I'm currently doing an aggregation query that groups all tracking id's and produces their count. I want to be able to filter this query by date.

my working query:

users = Tracking.objects.values( 'tracking_id' ).annotate(dcount=Count('tracking_id')).order_by('-dcount')[:100]

I've tried the following filter combinations but all result in syntax errors.

start_date = datetime.date(2012, 2, 1)
end_date = datetime.date(2012, 3, 2)
users = Tracking.objects.filter(date__range=(start_date, end_date).values( 'tracking_id' ).annotate(dcount=Count('tracking_id')).order_by('-dcount')[:100]

and

start_date = datetime.date(2012, 2, 1)
end_date = datetime.date(2012, 3, 2)
users = Tracking.objects.values( 'tracking_id' ).filter(date__range=(start_date, end_date).annotate(dcount=Count('tracking_id')).order_by('-dcount')[:100]

and

start_date = datetime.date(2012, 2, 1)
end_date = datetime.date(2012, 3, 2)
users = Tracking.objects.values( 'tracking_id' ).annotate(dcount=Count('tracking_id')).filter(date__range=(start_date, end_date).order_by('-dcount')[:100]

Any help would be greatly appreciated.


ANSWERS:


I think they result in syntax error because of a missing parenthesis (after end_date):

users = Tracking.objects.values( 'tracking_id' ).filter(date__range=(start_date, end_date) ...

should be

users = Tracking.objects.values( 'tracking_id' ).filter(date__range=(start_date, end_date)) ... 


 MORE:


 ? How to add a date filter to an Aggregation query in Django
 ? How to add a date filter to an Aggregation query in Django
 ? Django Query Filter
 ? Trouble filtering objects on basis of dates in django
 ? How to handle changing dates in Django Queries
 ? Reducing Django Database Queries
 ? Generic way to filter django query set by multiple fields (e.g. date)?
 ? In Django is there a way to aggregate over relationships with a condition on the related object
 ? In Django is there a way to aggregate over relationships with a condition on the related object
 ? In Django is there a way to aggregate over relationships with a condition on the related object