group_by() support

118 views
Skip to first unread message

David Cramer

unread,
Jul 27, 2007, 10:49:14 PM7/27/07
to Django developers
I committed a quick patch earlier to trunk that adds group_by()
support.

I can't run the tests on trunk, as we're not quite up that far, but it
should be working.

http://code.djangoproject.com/ticket/4997#comment:1

I plan to add having=[] support to extra as well this weekend.

David Cramer

unread,
Jul 27, 2007, 10:56:28 PM7/27/07
to Django developers
I noticed an issue while implementing this (could just be our
version).

When doing select={'choices': 'COUNT(...)'} It threw an error in
__set__ on the manager.add(*value) call (fields/related.py); choices
was a related_name call. It however did not error when doing
select={'choices': 'my_column'}

Russell Keith-Magee

unread,
Jul 27, 2007, 11:06:06 PM7/27/07
to django-d...@googlegroups.com
On 7/28/07, David Cramer <dcr...@gmail.com> wrote:
>
> I committed a quick patch earlier to trunk that adds group_by()
> support.

Hi David,

The idea of a 'group_by' and 'having' clause has been floated many
times before, and has been rejected in preference of an 'aggregations'
framework that provides a higher level, ORM-like interface (rather
than a SQL like interface) to the the ideas that group_by and having
expose. See Ticket #3566 for details on current thinking.

Adding this feature is waiting on a refactor of the internals of the
query engine. Malcolm is in the process of doing this refactor; any
patch against query.py is likely to be rendered invalid in the near
future.

Yours,
Russ Magee %-)

David Cramer

unread,
Jul 27, 2007, 11:21:39 PM7/27/07
to Django developers
QuerySet refactoring is like Django 1.0 ya? Never coming?

We've been struggling to use the Django ORM for a long while now,
because it has limited support for complex queries. GROUP BY is a
nescesity. I don't see any problem with redoing the QuerySet methods,
but there's no reason to not put in working fixes right now.

On Jul 27, 8:06 pm, "Russell Keith-Magee" <freakboy3...@gmail.com>
wrote:

Russell Keith-Magee

unread,
Jul 27, 2007, 11:56:00 PM7/27/07
to django-d...@googlegroups.com
On 7/28/07, David Cramer <dcr...@gmail.com> wrote:
>
> QuerySet refactoring is like Django 1.0 ya? Never coming?
>
> We've been struggling to use the Django ORM for a long while now,
> because it has limited support for complex queries. GROUP BY is a
> nescesity. I don't see any problem with redoing the QuerySet methods,
> but there's no reason to not put in working fixes right now.

Yes, there is a very good reason to not put the fixes in. We're not
going to add a feature to the db-api that we know, a priori, is going
to be removed (or at the very least substantially changed) in the near
future.

I know the Queryset refactor has been a long time coming. However, it
will happen pre-1.0.

If you _really_ need group-by/having _right now_, there is nothing
stopping you from putting your patch on your local version of Django.

Yours,
Russ Magee %-)

Tom Tobin

unread,
Jul 27, 2007, 11:59:35 PM7/27/07
to django-d...@googlegroups.com
On 7/27/07, David Cramer <dcr...@gmail.com> wrote:
>
> QuerySet refactoring is like Django 1.0 ya? Never coming?

The Django developers are ::gasp:: real people, with real jobs and
real lives. I see this perhaps more readily than most, since a few of
them are my co-workers. Considering all the other stuff they have to
do, it's amazing that they still find time to devote to Django.

If you want to help QuerySet refactoring along, jump in and offer to
lend Malcolm a hand; what you *shouldn't* do is toss out abusive,
thoughtless remarks like that.

David Cramer

unread,
Jul 28, 2007, 2:37:12 AM7/28/07
to Django developers
It's not abusive, and we use Django daily. I looked at the QuerySet
recactoring and I honestly don't like the aggregate() stuff.

We are real people, and developers also :)

On Jul 27, 8:59 pm, "Tom Tobin" <korp...@korpios.com> wrote:

Reply all
Reply to author
Forward
0 new messages