I am not sure what database you are using, but I just did this using a
raw query and postgresql's crosstab function.

http://www.postgresql.org/docs/current/static/tablefunc.html
http://docs.djangoproject.com/en/1.2/topics/db/sql/#executing-custom-sql-directly

On Feb 18, 7:25 am, Derek <gamesb...@gmail.com> wrote:
> On Feb 17, 10:52 pm, Phlip <phlip2...@gmail.com> wrote:
>
>
>
>
>
> > Djangoists:
>
> > I have a database table like this...
>
> >   red, 1
> >   red, 2
> >   red, 15
> >   blue, 18
> >   blue, 20
>
> > ...and I want to read it into an array like this:
>
> >   [ ['red', [1,2,15]], ['blue', [18,20]], ]
>
> > Of course I can use values_list('color', 'number'), and then re-pack
> > the array with a for-loop.
>
> > Do QuerySet aggregations and annotations offer some way to push that
> > query into the database?
>
> Assuming you want an output in array format (as per the first part of
> your 
> question):http://stackoverflow.com/questions/1859031/how-could-create-a-crossta...

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

Reply via email to