Changes between Initial Version and Version 1 of Ticket #29561


Ignore:
Timestamp:
Jul 11, 2018, 9:45:35 AM (6 years ago)
Author:
Gabriel Oliveira
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #29561 – Description

    initial v1  
    7979
    8080How may I accomplish that, even if I have to use the extra fields, or even RawSQL class ?
     81
     82Right now I'm doing:
     83
     84{{{#!python
     85with connection.cursor() as c:
     86    c.execute('SELECT q.day, q.temperature FROM (%s) AS q WHERE q.temperature IS DISTINCT FROM q.prev_temp' % str(Weather.objects.annotate(prev_temp=Window(expression=Lead('temperature'), order_by=F('day').desc())).order_by('-day').values('day','temperature', 'prev_temp').query))
     87    result = c.fetchall()
     88}}}
     89
     90Important to note that I couldn't use the str(queryset.query) as parameter to the c.execute. I had to do a python replace.
     91I.e, had to use  ('...%s...' % parameter)   instead of c.execute ('...%s...', [parameter])
Back to Top