On 18 Feb, 19:33, Jacob Kaplan-Moss <jacob.kaplanm...@gmail.com> wrote: > On Wed, Feb 18, 2009 at 12:24 PM, Deniz Dogan <deniz.a.m.do...@gmail.com> > wrote: > > I'm sorry about that, I meant something like this: > > > { 2008-01-02 : [Bike 1, Bike 2], > > 2008-02-09 : [Bike 7, Bike 4] } > > Well, you can't do this with the aggregation API because you can't do > that is SQL. Remember: there's no such thing as a "list" in a > relational database.
Oops, didn't really think about that! > However, this is pretty easy to do just in Python using > ``itertools.groupby`` > (seehttp://docs.python.org/library/itertools.html#itertools.groupby):: > > >>> bikes = Bike.objects.all() > >>> for d, bl in itertools.groupby(bikes, lambda b: b.production_date): > ... print d, list(bl) > > 2008-01-01 [<Bike: 1>, <Bike: 2>] > 2008-01-02 [<Bike: 3>] > 2008-01-03 [<Bike: 4>] > 2008-01-04 [<Bike: 5>, <Bike: 6>] > 2008-01-05 [<Bike: 7>] > > The ORM's not a crutch; it doesn't bother with tasks you can easily do > using the tools Python gives you. Mm, and in case you're keeping > track, this is quite easy on the database; just a single query. > > Hope that's closer to what you had in mind, > > Jacob Thanks a lot! I had just completed a little hack of my own for this, but I'll make sure to check itertools out, because it seems pretty cool. Deniz --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---