Opened 6 years ago
Closed 6 years ago
#29066 closed Bug (fixed)
Allow negating query expressions
Reported by: | Matthew Pava | Owned by: | Priyansh Saxena |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Adam Johnson | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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'
Change History (8)
comment:1 Changed 6 years ago by
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 Changed 6 years ago by
Owner: | changed from nobody to Priyansh Saxena |
---|---|
Status: | new → assigned |
comment:4 Changed 6 years ago by
Cc: | Adam Johnson added |
---|
comment:5 Changed 6 years ago by
Needs tests: | set |
---|
comment:6 Changed 6 years ago by
Needs tests: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
comment:7 Changed 6 years ago by
Summary: | Sum does not support __neg__ → Allow negating query expressions |
---|
Note: See
TracTickets for help on using
tickets.
I guess we could add support for
__neg__
, in the mean timeSum('field') * -1
which goes through__mul__
should work just fine.