Allow negating query expressions
I am trying to negate the sum of values in my model, and the workaround is to multiply by Value(-1)
.
I get this error when I try to annotate by -Sum('field')
:
TypeError
bad operand type for unary -: 'Sum'
Triage Stage: |
Unreviewed → Accepted
|
Owner: |
changed from nobody to Priyansh Saxena
|
Status: |
new → assigned
|
Needs tests: |
unset
|
Triage Stage: |
Accepted → Ready for checkin
|
Summary: |
Sum does not support __neg__ → Allow negating query expressions
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
I guess we could add support for
__neg__
, in the mean timeSum('field') * -1
which goes through__mul__
should work just fine.