Hi,

I've recently faced to an issue, which I believe is a wrong behavior.
Suppose I have the following model:

class ClassA(models.Model):
    date_f = models.DateField()
    char_f = models.CharField(max_length=10)

And suppose I have 3 entries in this model:
('2011-11-1', string1),
('2011-12-1', string1),
('2011-12-1', string2)

To calculate counts for each "char_f" field:
ClassA.objects.values("char_f").annotate(count=Count('char_f'))

The result is:
[{'char_f': u'string1', 'count': 2}, {'char_f': u'string2', 'count':
1}]


But when I added ordering in ClassA model

class ClassA(models.Model):
    ....
    class Meta:
        ordering = ("date_f",)

and ran the same query:
ClassA.objects.values("char_f").annotate(count=Count('char_f'))

I've got the following
[{'char_f': u'string1', 'count': 1}, {'char_f': u'string1', 'count':
1}, {'char_f': u'string2', 'count': 1}]

I think the ordering should somehow be ignored in such cases, to
prevent it appearing in sql query
What do you think, is this a correct behavior?

Thanks,
Hovo

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to