Ticket #10290: 10290.diff

File 10290.diff, 1.1 KB (added by Erin Kelly, 16 years ago)
  • django/db/models/sql/query.py

     
    703703        result = []
    704704        if self.group_by is not None:
    705705            group_by = self.group_by or []
    706             for col in group_by + self.related_select_cols + self.extra_select.keys():
     706            extra_selects = [v[0] for v in self.extra_select.itervalues()]
     707            for col in group_by + self.related_select_cols + extra_selects:
    707708                if isinstance(col, (list, tuple)):
    708709                    result.append('%s.%s' % (qn(col[0]), qn(col[1])))
    709710                elif hasattr(col, 'as_sql'):
     
    791792                if distinct and col not in select_aliases:
    792793                    ordering_aliases.append(elt)
    793794                result.append('%s %s' % (elt, order))
    794                 group_by.append(elt)
     795                group_by.append(self.extra_select[col][0])
    795796        self.ordering_aliases = ordering_aliases
    796797        return result, group_by
    797798
Back to Top