On Fri, Feb 13, 2009 at 6:54 PM, Alessandro <alessandro.ron...@gmail.com> wrote: > > > 2009/2/10 Alessandro <alessandro.ron...@gmail.com> >> >> >> 2009/2/10 Russell Keith-Magee <freakboy3...@gmail.com> >>> >>> >>> i.e., plural modules, not singular module, in the Max lookup. It's the >>> reverse lookup name for the module relationship on Module_scheme. For >>> future reference, the message on the FieldError tells you the right >>> name - modules. > > Is it possible to do a group by of a time selection, like GROUP BY > DAY(time_field) ?
Enabling grouping on fields modified by a function wasn't explicitly part of the original design specification. However, once I fix #10132, you may be able to do this by putting the DAY(time_field) portion into an extra column, and naming the extra column in a values clause; something like: Model.objects.extra(select={'giorno':''DAY(time_field)'}).values('giorno').annotate(SUM('peak')) #10132 is the ticket I'm working on right now, but fixing it has revealed a few other problems along the way. I hope to commit a fix in the next day or so. > I need to make a query like this: > > SELECT SUM(peak), giorno FROM (SELECT MAX(power_peakdaily) AS peak > ,DAY(time) AS giorno FROM fotovoltaico_modules, fotovoltaico_module_scheme > WHERE fotovoltaico_module_scheme.plant_id=%s AND year(time)= %s AND > month(time)=%s AND scheme_id=fotovoltaico_module_scheme.id GROUP BY > fotovoltaico_module_scheme.id, DAY(time) ORDER BY DAY(time)) AS tabella > GROUP BY giorno ;"%( year, month, self.id)) Annotating over subqueries wasn't explicitly part of the design spec, either; again, you will probably need to fall back onto an extra clause, this time with a 'tables' parameter. You're going to need to play around a bit to see what works, though. Yours, Russ Magee %-) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---