﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
10248	Calling .dates on a annotated queryset gives wrong sql	oyvind		"Example models

{{{
#!python

class Photo(models.Model):
    title = models.CharField(max_length=30)

class Gallery(models.Model):
    
    title = models.CharField(max_length=30)
    photos = models.ManyToManyField(Photo)
    date_published = models.DateField()

}}}

Query:

{{{
#!python

from django.db import connection
from django.db.models import Count

Gallery.objects.dates('date_published', 'year')

print connection.queries[-1]

Gallery.objects.annotate(photo_count=Count('photos__id')).dates('date_published', 'year')

print connection.queries[-1]

}}}


"		closed	Database layer (models, ORM)	dev		fixed	annotate dates queryset		Accepted	1	0	0	0	0	0
