I noticed that when using group by with Django ORM, the group by conditions are duplicated. Then I found more information about it in here. Fortunately there is a patch, and the diff file.
The patch should be applied to compiler.py module. On my Ubuntu 10.04 system it is located: