Hey, I have a model which monitors the prices of certain items at certain markets daily.
precios/models: ... class Prueba(Approvable): mercado = models.ForeignKey(Mercado) producto = models.ForeignKey(Producto) fecha = models.DateField() minimo = models.DecimalField(max_digits=10,decimal_places=2) maximo = models.DecimalField(max_digits=10,decimal_places=2) ... Now I want to be able to get the monthly average prices over a certain period of time. At first I tried this (using postgresql): queryset=PrecioPrueba.objects.filter(producto=producto).filter (mercado=mercado).filter(fecha__range[start_date,end_date]).extra (select={'fecha':"date_trunc('"+frecuencia+'",fecha)"}).values ('fecha','producto','mercado','maximo','minimo').annotate(maximo=Avg ('maximo'),minimo=Avg('minimo')).order_by('fecha') but that just gave me all the values with the date set to the first of the month, so I figured django isn't up for the job yet. Instead I tried doing it this way: ... from django.db import connection cursor = connection.cursor() cursor.execute("select producto_id as producto, mercado_id as mercado, date_trunc('month',fecha) as fecha, avg(maximo) as maximo, avg(minimo) as minimo from precios_prueba where producto_id = %s and mercado_id = %s group by date_trunc('month',fecha), producto_id, mercado_id order by fecha;", [producto,mercado]) queryset=[] for row in cursor.fetchall(): row_dic={'fecha':row[2],'maximo':row[3],'minimo':row [4],'producto':row[0],'mercado':row[1]} queryset.append(row) ... This works in the shell, but using it on a real live site I get the error: can't adapt without any additional infos, other than that it originates from the psycopg2-connection. Any clues? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---