Created
December 14, 2019 17:29
-
-
Save walison17/56d8b9389a3ee918e97a0851c727e5ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
q = ( | |
Lancamento | |
.objects | |
.annotate( | |
val=models.Case( | |
When(account_from=8, then=models.F('valor') * -1), | |
default_value=models.F('valor'), | |
output_field=models.DecimalField() | |
) | |
) | |
.filter( | |
models.Q(account_to=8) | models.Q(account_from=8) | |
) | |
.values('account_from', 'account_to', 'val') | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment