I have to get the max value of a model grouped by a field. The RAW SQL query is this:
SELECT max(energy_tot) FROM fotovoltaico_modules,fotovoltaico_module_scheme WHERE fotovoltaico_module_scheme.plant_id = 3 AND fotovoltaico_modules.scheme_id = fotovoltaico_module_scheme.id GROUP BY fotovoltaico_modules.scheme_id; I haven't found any way to make the aggregation work with the group by. This is my model: http://dpaste.com/118868/ I've tried also: qs = Modules.objects.filter(scheme__plant=3).order_by("-time") qs.query.group_by = ["fotovoltaico_modules.scheme_id"] but it loose the order by and the results are not the same I want. Thanks in advance! -- Alessandro Ronchi Skype: aronchi http://www.alessandroronchi.net SOASI Soc.Coop. - www.soasi.com Sviluppo Software e Sistemi Open Source Sede: Via Poggiali 2/bis, 47100 Forlì (FC) Tel.: +39 0543 798985 - Fax: +39 0543 579928 Rispetta l'ambiente: se non ti è necessario, non stampare questa mail --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---