Opened 8 years ago
Closed 8 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 by , 8 years ago
| Triage Stage: | Unreviewed → Accepted | 
|---|
comment:2 by , 8 years ago
| Owner: | changed from to | 
|---|---|
| Status: | new → assigned | 
comment:4 by , 8 years ago
| Cc: | added | 
|---|
comment:5 by , 8 years ago
| Needs tests: | set | 
|---|
comment:6 by , 8 years ago
| Needs tests: | unset | 
|---|---|
| Triage Stage: | Accepted → Ready for checkin | 
comment:7 by , 8 years ago
| 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') * -1which goes through__mul__should work just fine.