python - Union on ValuesQuerySet in django -


I'm looking for a way to get a team of queries in the Digengo. What I have read, query1 | Query 2 to take the union ... This does not seem to work when using values ​​() However. I leave the use of values ​​until I take the union, but I need to use the annotate to take the sum of a field and filter it on it, and since there is no way of "group" I have to use values ​​() I The other suggestions that I had to read were to use the Q objects, but I could not work in any way.

Do I need to use direct SQL or is there a way to do this?

What do I need:

  q1 = mymodel.objects.filter (date__lt = '2010-06-11'). Value ('Field 1', 'Field2') Anotate (volume = sum ('volume')). Out (Volume = 0) q2 = mymodel.objects.values ​​('field1', 'field2'). Annotated (volume = sum ('quantity')). (Volsum = 0) query = q1 | Q2  

but it does not work and as far as I know that I need a "value" part because there is no other way to know the amount because it is a 15 column table .

QuerySet.values ​​() a QuerySet does not return, but rather convert them to a ValuesQuerySet , which does not support this operation with the list .

  query = list (q1) + list (q2)  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -